departures: profile flag for getPasslist & stbFilterEquiv

This commit is contained in:
Jannis R 2018-12-30 15:21:04 +01:00
parent b55c2c1579
commit 5d0096c596
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 21 additions and 11 deletions

View file

@ -49,6 +49,13 @@ const createClient = (profile, userAgent, request = _request) => {
throw new Error('type must be a non-empty string.') throw new Error('type must be a non-empty string.')
} }
if (!profile.departuresGetPasslist && ('stopovers' in opt)) {
throw new Error('opt.stopovers is not supported by this endpoint')
}
if (!profile.departuresStbFltrEquiv && ('includeRelatedStations' in opt)) {
throw new Error('opt.includeRelatedStations is not supported by this endpoint')
}
opt = Object.assign({ opt = Object.assign({
direction: null, // only show departures heading to this station direction: null, // only show departures heading to this station
duration: 10, // show departures for the next n minutes duration: 10, // show departures for the next n minutes
@ -64,19 +71,20 @@ const createClient = (profile, userAgent, request = _request) => {
const products = profile.formatProductsFilter(opt.products || {}) const products = profile.formatProductsFilter(opt.products || {})
const dir = opt.direction ? profile.formatStation(opt.direction) : null const dir = opt.direction ? profile.formatStation(opt.direction) : null
const req = {
type,
date: profile.formatDate(profile, opt.when),
time: profile.formatTime(profile, opt.when),
stbLoc: station,
dirLoc: dir,
jnyFltrL: [products],
dur: opt.duration
}
if (profile.departuresGetPasslist) req.getPasslist = !!opt.stopovers
if (profile.departuresStbFltrEquiv) req.stbFltrEquiv = !opt.includeRelatedStations
return request(profile, userAgent, opt, { return request(profile, userAgent, opt, {
meth: 'StationBoard', meth: 'StationBoard',
req: { req
type,
date: profile.formatDate(profile, opt.when),
time: profile.formatTime(profile, opt.when),
stbLoc: station,
dirLoc: dir,
jnyFltrL: [products],
dur: opt.duration,
getPasslist: !!opt.stopovers,
stbFltrEquiv: !opt.includeRelatedStations
}
}) })
.then((d) => { .then((d) => {
if (!Array.isArray(d.jnyL)) return [] if (!Array.isArray(d.jnyL)) return []

View file

@ -66,6 +66,8 @@ const defaultProfile = {
filters, filters,
journeysNumF: true, // `journeys()` method: support for `numF` field? journeysNumF: true, // `journeys()` method: support for `numF` field?
departuresGetPasslist: true, // `departures()` method: support for `getPasslist` field?
departuresStbFltrEquiv: true, // `departures()` method: support for `stbFltrEquiv` field?
trip: false, trip: false,
radar: false, radar: false,
refreshJourney: true refreshJourney: true