mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
query journeys
This commit is contained in:
parent
c20fd35c67
commit
2c2826217e
2 changed files with 55 additions and 4 deletions
57
index.js
57
index.js
|
@ -28,9 +28,7 @@ const createClient = (profile) => {
|
||||||
time: profile.formatTime(profile, opt.when),
|
time: profile.formatTime(profile, opt.when),
|
||||||
stbLoc: profile.formatStation(station),
|
stbLoc: profile.formatStation(station),
|
||||||
dirLoc: dir,
|
dirLoc: dir,
|
||||||
jnyFltrL: [
|
jnyFltrL: [products],
|
||||||
profile.formatProducts(opt.products) // todo
|
|
||||||
],
|
|
||||||
dur: opt.duration,
|
dur: opt.duration,
|
||||||
getPasslist: false
|
getPasslist: false
|
||||||
}
|
}
|
||||||
|
@ -42,7 +40,58 @@ const createClient = (profile) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return {departures}
|
const journeys = (from, to, opt = {}) => {
|
||||||
|
from = profile.formatLocation(profile, from)
|
||||||
|
to = profile.formatLocation(profile, to)
|
||||||
|
|
||||||
|
opt = Object.assign({
|
||||||
|
results: 5, // how many journeys?
|
||||||
|
via: null, // let journeys pass this station?
|
||||||
|
passedStations: false, // return stations on the way?
|
||||||
|
transfers: 5, // maximum of 5 transfers
|
||||||
|
transferTime: 0, // minimum time for a single transfer in minutes
|
||||||
|
// todo: does this work with every endpoint?
|
||||||
|
accessibility: 'none', // 'none', 'partial' or 'complete'
|
||||||
|
bike: false, // only bike-friendly journeys
|
||||||
|
}, opt)
|
||||||
|
if (opt.via) opt.via = profile.formatLocation(profile, opt.via)
|
||||||
|
opt.when = opt.when || new Date()
|
||||||
|
const products = profile.formatProducts(opt.products || {})
|
||||||
|
|
||||||
|
const query = profile.transformJourneysQuery({
|
||||||
|
outDate: profile.formatDate(profile, opt.when),
|
||||||
|
outTime: profile.formatTime(profile, opt.when),
|
||||||
|
numF: opt.results,
|
||||||
|
getPasslist: !!opt.passedStations,
|
||||||
|
maxChg: opt.transfers,
|
||||||
|
minChgTime: opt.transferTime,
|
||||||
|
depLocL: [from],
|
||||||
|
viaLocL: opt.via ? [opt.via] : null,
|
||||||
|
arrLocL: [to],
|
||||||
|
jnyFltrL: [products],
|
||||||
|
|
||||||
|
// todo: what is req.gisFltrL?
|
||||||
|
// todo: what are all these for?
|
||||||
|
getPT: true,
|
||||||
|
outFrwd: true,
|
||||||
|
getTariff: false,
|
||||||
|
getIV: false, // walk & bike as alternatives?
|
||||||
|
getPolyline: false // shape for displaying on a map?
|
||||||
|
}, opt)
|
||||||
|
|
||||||
|
return request(profile, {
|
||||||
|
cfg: {polyEnc: 'GPA'},
|
||||||
|
meth: 'TripSearch',
|
||||||
|
req: query
|
||||||
|
})
|
||||||
|
.then((d) => {
|
||||||
|
if (!Array.isArray(d.outConL)) return []
|
||||||
|
const parse = profile.parseJourney(profile, d.locations, d.lines, d.remarks)
|
||||||
|
return d.outConL.map(parse)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return {departures, journeys}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = createClient
|
module.exports = createClient
|
||||||
|
|
|
@ -28,6 +28,8 @@ const defaultProfile = {
|
||||||
transformReqBody: id,
|
transformReqBody: id,
|
||||||
transformReq: id,
|
transformReq: id,
|
||||||
|
|
||||||
|
transformJourneysQuery: id,
|
||||||
|
|
||||||
parseDateTime,
|
parseDateTime,
|
||||||
parseDeparture,
|
parseDeparture,
|
||||||
parseJourney,
|
parseJourney,
|
||||||
|
|
Loading…
Add table
Reference in a new issue