diff --git a/index.js b/index.js index ff8b1401..73615013 100644 --- a/index.js +++ b/index.js @@ -28,9 +28,7 @@ const createClient = (profile) => { time: profile.formatTime(profile, opt.when), stbLoc: profile.formatStation(station), dirLoc: dir, - jnyFltrL: [ - profile.formatProducts(opt.products) // todo - ], + jnyFltrL: [products], dur: opt.duration, 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 diff --git a/lib/default-profile.js b/lib/default-profile.js index c5257b82..5b1681b8 100644 --- a/lib/default-profile.js +++ b/lib/default-profile.js @@ -28,6 +28,8 @@ const defaultProfile = { transformReqBody: id, transformReq: id, + transformJourneysQuery: id, + parseDateTime, parseDeparture, parseJourney,