diff --git a/index.js b/index.js index 47aba5f9..ff8b1401 100644 --- a/index.js +++ b/index.js @@ -9,8 +9,40 @@ const createClient = (profile) => { throw new Error('profile.timezone must be a string.') } - const client = data => request(profile, data) - return client + const departures = (station, opt = {}) => { + 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