query departures

This commit is contained in:
Jannis R 2017-11-12 18:06:16 +01:00
parent eb98123e5b
commit f86f908dcc
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -9,8 +9,40 @@ const createClient = (profile) => {
throw new Error('profile.timezone must be a string.') throw new Error('profile.timezone must be a string.')
} }
const client = data => request(profile, data) const departures = (station, opt = {}) => {
return client if ('string' !== typeof station) throw new Error('station must be a string.')
opt = Object.assign({
direction: null, // only show departures heading to this station
duration: 10 // show departures for the next n minutes
}, opt)
opt.when = opt.when || new Date()
const products = profile.formatProducts(opt.products || {})
const dir = opt.direction ? profile.formatStation(opt.direction) : null
return request(profile, {
meth: 'StationBoard',
req: {
type: 'DEP',
date: profile.formatDate(profile, opt.when),
time: profile.formatTime(profile, opt.when),
stbLoc: profile.formatStation(station),
dirLoc: dir,
jnyFltrL: [
profile.formatProducts(opt.products) // todo
],
dur: opt.duration,
getPasslist: false
}
})
.then((d) => {
if (!Array.isArray(d.jnyL)) return [] // todo: throw err?
const parse = profile.parseDeparture(profile, d.locations, d.lines, d.remarks)
return d.jnyL.map(parse)
})
}
return {departures}
} }
module.exports = createClient module.exports = createClient