From ac9819b1dd547b2249a76211c8182010dfa095c0 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 26 Jun 2018 17:11:25 +0200 Subject: [PATCH] query arrivals :sparkles:, docs :memo: --- docs/arrivals.md | 3 +++ docs/readme.md | 1 + index.js | 21 ++++++++++++--------- p/db/example.js | 1 + p/insa/example.js | 1 + p/nahsh/example.js | 1 + p/oebb/example.js | 1 + p/vbb/example.js | 1 + 8 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 docs/arrivals.md diff --git a/docs/arrivals.md b/docs/arrivals.md new file mode 100644 index 00000000..683c47ed --- /dev/null +++ b/docs/arrivals.md @@ -0,0 +1,3 @@ +# `arrivals(station, [opt])` + +Just like [`departures(station, [opt])`](departures.md), except that it gives arrival times instead of departure times. diff --git a/docs/readme.md b/docs/readme.md index fa511bb8..cce0f86a 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -3,6 +3,7 @@ - [`journeys(from, to, [opt])`](journeys.md) – get journeys between locations - [`journeyLeg(ref, lineName, [opt])`](journey-leg.md) – get details for a leg of a journey - [`departures(station, [opt])`](departures.md) – query the next departures at a station +- [`arrivals(station, [opt])`](arrivals.md) – query the next arrivals at a station - [`locations(query, [opt])`](locations.md) – find stations, POIs and addresses - [`station(id)`](station.md) – get details about a station - [`nearby(location, [opt])`](nearby.md) – show stations & POIs around diff --git a/index.js b/index.js index c3a2d4fd..1d0cde19 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ const createClient = (profile, request = _request) => { } validateProfile(profile) - const _stationBoard = (station, type, opt = {}) => { + const _stationBoard = (station, type, parser, opt = {}) => { if (isObj(station)) station = profile.formatStation(station.id) else if ('string' === typeof station) station = profile.formatStation(station) else throw new Error('station must be an object or a string.') @@ -43,7 +43,7 @@ const createClient = (profile, request = _request) => { return request(profile, opt, { meth: 'StationBoard', req: { - type: 'DEP', + type, date: profile.formatDate(profile, opt.when), time: profile.formatTime(profile, opt.when), stbLoc: station, @@ -53,13 +53,9 @@ const createClient = (profile, request = _request) => { getPasslist: false } }) - } - - const departures = (station, opt = {}) => { - return _stationBoard(station, 'DEP', opt) .then((d) => { - if (!Array.isArray(d.jnyL)) return [] // todo: throw err? - const parse = profile.parseDeparture(profile, opt, { + if (!Array.isArray(d.jnyL)) return [] + const parse = parser(profile, opt, { locations: d.locations, lines: d.lines, hints: d.hints, @@ -70,6 +66,13 @@ const createClient = (profile, request = _request) => { }) } + const departures = (station, opt = {}) => { + return _stationBoard(station, 'DEP', profile.parseDeparture, opt) + } + const arrivals = (station, opt = {}) => { + return _stationBoard(station, 'ARR', profile.parseArrival, opt) + } + const journeys = (from, to, opt = {}) => { from = profile.formatLocation(profile, from, 'from') to = profile.formatLocation(profile, to, 'to') @@ -401,7 +404,7 @@ const createClient = (profile, request = _request) => { }) } - const client = {departures, journeys, locations, station, nearby} + const client = {departures, arrivals, journeys, locations, station, nearby} if (profile.journeyLeg) client.journeyLeg = journeyLeg if (profile.radar) client.radar = radar Object.defineProperty(client, 'profile', {value: profile}) diff --git a/p/db/example.js b/p/db/example.js index f9fe23e6..2f99d919 100644 --- a/p/db/example.js +++ b/p/db/example.js @@ -8,6 +8,7 @@ const client = createClient(dbProfile) // Berlin Jungfernheide to München Hbf client.journeys('8011167', '8000261', {results: 1, tickets: true}) // client.departures('8011167', {duration: 1}) +// client.arrivals('8011167', {duration: 10}) // client.locations('Berlin Jungfernheide') // client.locations('Atze Musiktheater', {poi: true, addressses: false, fuzzy: false}) // client.station('8000309') // Regensburg Hbf diff --git a/p/insa/example.js b/p/insa/example.js index 2260f34b..190f8fa9 100644 --- a/p/insa/example.js +++ b/p/insa/example.js @@ -8,6 +8,7 @@ const client = createClient(insaProfile) // from Magdeburg-Neustadt to Magdeburg-Buckau client.journeys('008010226', '008013456', {results: 1}) // client.departures('008010226', { duration: 5 }) +// client.arrivals('8010226', {duration: 10}) // client.locations('Magdeburg Hbf', {results: 2}) // client.locations('Kunstmuseum Kloster Unser Lieben Frauen Magdeburg', {results: 2}) // client.station('008010226') // Magdeburg-Neustadt diff --git a/p/nahsh/example.js b/p/nahsh/example.js index f3ec6237..986e01be 100644 --- a/p/nahsh/example.js +++ b/p/nahsh/example.js @@ -8,6 +8,7 @@ const client = createClient(nahshProfile) // Flensburg Hbf to Kiel Hbf client.journeys('8000103', '8000199', {results: 10, tickets: true}) // client.departures('8000199', {duration: 10}) +// client.arrivals('8000199', {duration: 5}) // client.journeyLeg('1|30161|5|100|14032018', 'Bus 52') // client.locations('Schleswig', {results: 1}) // client.station('706990') // Kiel Holunderbusch diff --git a/p/oebb/example.js b/p/oebb/example.js index 4f780f66..208bc367 100644 --- a/p/oebb/example.js +++ b/p/oebb/example.js @@ -8,6 +8,7 @@ const client = createClient(oebbProfile) // Wien Westbahnhof to Salzburg Hbf client.journeys('1291501', '8100002', {results: 1}) // client.departures('8100002', {duration: 1}) +// client.arrivals('8100002', {duration: 10}) // client.locations('Salzburg', {results: 2}) // client.station('8100173') // Graz Hbf // client.nearby(47.812851, 13.045604, {distance: 60}) diff --git a/p/vbb/example.js b/p/vbb/example.js index 1234692a..e2e4027a 100644 --- a/p/vbb/example.js +++ b/p/vbb/example.js @@ -8,6 +8,7 @@ const client = createClient(vbbProfile) // Hauptbahnhof to Charlottenburg client.journeys('900000003201', '900000024101', {results: 1, polylines: true}) // client.departures('900000013102', {duration: 1}) +// client.arrivals('900000013102', {duration: 10}) // client.locations('Alexanderplatz', {results: 2}) // client.station('900000042101') // Spichernstr // client.nearby(52.5137344, 13.4744798, {distance: 60})