mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
refreshJourney method
This commit is contained in:
parent
3dc492b686
commit
5b754aaa55
2 changed files with 42 additions and 3 deletions
42
index.js
42
index.js
|
@ -59,7 +59,7 @@ const createClient = (profile, userAgent, request = _request) => {
|
||||||
dirLoc: dir,
|
dirLoc: dir,
|
||||||
jnyFltrL: [products],
|
jnyFltrL: [products],
|
||||||
dur: opt.duration,
|
dur: opt.duration,
|
||||||
getPasslist: false, // todo: what is this?
|
getPasslist: false, // todo
|
||||||
stbFltrEquiv: !opt.includeRelatedStations
|
stbFltrEquiv: !opt.includeRelatedStations
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -224,6 +224,44 @@ const createClient = (profile, userAgent, request = _request) => {
|
||||||
return more(when, journeysRef)
|
return more(when, journeysRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const refreshJourney = (refreshToken, opt = {}) => {
|
||||||
|
if ('string' !== typeof refreshToken || !refreshToken) {
|
||||||
|
new Error('refreshToken must be a non-empty string.')
|
||||||
|
}
|
||||||
|
|
||||||
|
opt = Object.assign({
|
||||||
|
stopovers: false, // return stations on the way?
|
||||||
|
tickets: false, // return tickets?
|
||||||
|
polylines: false, // return leg shapes?
|
||||||
|
remarks: true // parse & expose hints & warnings?
|
||||||
|
}, opt)
|
||||||
|
|
||||||
|
return request(profile, opt, {
|
||||||
|
meth: 'Reconstruction',
|
||||||
|
req: {
|
||||||
|
ctxRecon: refreshToken,
|
||||||
|
getIST: true, // todo: make an option
|
||||||
|
getPasslist: !!opt.stopovers,
|
||||||
|
getPolyline: !!opt.polylines,
|
||||||
|
getTariff: !!opt.tickets
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then((d) => {
|
||||||
|
if (!Array.isArray(d.outConL) || !d.outConL[0]) {
|
||||||
|
throw new Error('invalid response')
|
||||||
|
}
|
||||||
|
|
||||||
|
const parse = profile.parseJourney(profile, opt, {
|
||||||
|
locations: d.locations,
|
||||||
|
lines: d.lines,
|
||||||
|
hints: d.hints,
|
||||||
|
warnings: d.warnings,
|
||||||
|
polylines: opt.polylines && d.common.polyL || []
|
||||||
|
})
|
||||||
|
return parse(d.outConL[0])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const locations = (query, opt = {}) => {
|
const locations = (query, opt = {}) => {
|
||||||
if (!isNonEmptyString(query)) {
|
if (!isNonEmptyString(query)) {
|
||||||
throw new Error('query must be a non-empty string.')
|
throw new Error('query must be a non-empty string.')
|
||||||
|
@ -420,7 +458,7 @@ const createClient = (profile, userAgent, request = _request) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = {departures, arrivals, journeys, locations, station, nearby}
|
const client = {departures, arrivals, journeys, refreshJourney, locations, station, nearby}
|
||||||
if (profile.trip) client.trip = trip
|
if (profile.trip) client.trip = trip
|
||||||
if (profile.radar) client.radar = radar
|
if (profile.radar) client.radar = radar
|
||||||
Object.defineProperty(client, 'profile', {value: profile})
|
Object.defineProperty(client, 'profile', {value: profile})
|
||||||
|
|
|
@ -20,7 +20,8 @@ const createParseJourney = (profile, opt, data) => {
|
||||||
const legs = j.secL.map(leg => parseLeg(j, leg))
|
const legs = j.secL.map(leg => parseLeg(j, leg))
|
||||||
const res = {
|
const res = {
|
||||||
type: 'journey',
|
type: 'journey',
|
||||||
legs
|
legs,
|
||||||
|
refreshToken: j.ctxRecon || null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt.remarks && Array.isArray(j.msgL)) {
|
if (opt.remarks && Array.isArray(j.msgL)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue