From 58f183506ecd47adaed0869efb2eacef12578991 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 28 Jun 2018 13:00:33 +0200 Subject: [PATCH] option to parse station lines, default off :boom:, adapt docs :memo: --- docs/changelog.md | 1 + docs/departures.md | 3 ++- docs/locations.md | 1 + docs/migrating-to-3.md | 4 ++++ docs/nearby.md | 1 + docs/readme.md | 2 +- docs/station.md | 9 ++++++++- index.js | 13 +++++++++---- p/db/example.js | 2 +- p/insa/example.js | 2 +- p/nahsh/example.js | 2 +- p/oebb/example.js | 2 +- p/vbb/example.js | 4 ++-- parse/location.js | 6 +++++- 14 files changed, 38 insertions(+), 14 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 2f72255e..49504595 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -28,6 +28,7 @@ This version is not fully backwords-compatible. Check out [the migration guide]( - 3e672ee `journeys()`/`journeyLeg()`: `stopover.station` → `stopover.stop` - 2e6aefe journey leg, departure, movement: `journeyId` -> `tripId` - 8881d8a & b6fbaa5: change parsers signature to `parse…(profile, opt, data)` +- cabe5fa: option to parse & expose `station.lines`, default off ## `2.7.0` diff --git a/docs/departures.md b/docs/departures.md index 7277255c..d331da07 100644 --- a/docs/departures.md +++ b/docs/departures.md @@ -26,7 +26,8 @@ With `opt`, you can override the default options, which look like this: // todo: products when: new Date(), 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 + stationLines: false // parse & expose lines of the station? } ``` diff --git a/docs/locations.md b/docs/locations.md index 8b9d17ab..8337823d 100644 --- a/docs/locations.md +++ b/docs/locations.md @@ -11,6 +11,7 @@ With `opt`, you can override the default options, which look like this: , stations: true , addresses: true , poi: true // points of interest + , stationLines: false // parse & expose lines of the station? } ``` diff --git a/docs/migrating-to-3.md b/docs/migrating-to-3.md index 668e67a5..4bda6e90 100644 --- a/docs/migrating-to-3.md +++ b/docs/migrating-to-3.md @@ -47,3 +47,7 @@ - `parseNearby` - `parsePolyline` - `parseStopover` + +## If you use `station.lines` array anywhere… + +…add the `stationLines: true` option to the method call, e.g. `hafas.departures('123', {stationLines: true}). cabe5fa diff --git a/docs/nearby.md b/docs/nearby.md index 397162f0..c75d0f03 100644 --- a/docs/nearby.md +++ b/docs/nearby.md @@ -11,6 +11,7 @@ With `opt`, you can override the default options, which look like this: distance: null, // maximum walking distance in meters poi: false, // return points of interest? stations: true, // return stations? + stationLines: false // parse & expose lines of the station? } ``` diff --git a/docs/readme.md b/docs/readme.md index cce0f86a..61699d2d 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -5,7 +5,7 @@ - [`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 +- [`station(id, [opt])`](station.md) – get details about a station - [`nearby(location, [opt])`](nearby.md) – show stations & POIs around - [`radar(north, west, south, east, [opt])`](radar.md) – find all vehicles currently in a certain area diff --git a/docs/station.md b/docs/station.md index 1a0dd31b..db780f5b 100644 --- a/docs/station.md +++ b/docs/station.md @@ -1,4 +1,4 @@ -# `station(id)` +# `station(id, [opt])` `id` must be in one of these formats: @@ -19,6 +19,13 @@ } ``` +With `opt`, you can override the default options, which look like this: + +```js +{ + stationLines: false // parse & expose lines of the station? +} + ## Response As an example, we're going to use the [VBB profile](../p/vbb): diff --git a/index.js b/index.js index a83218d9..dfe795e2 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,8 @@ const createClient = (profile, request = _request) => { opt = Object.assign({ 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 + stationLines: false // parse & expose lines of the station? }, opt) opt.when = new Date(opt.when || Date.now()) if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid') @@ -222,7 +223,8 @@ const createClient = (profile, request = _request) => { results: 10, // how many search results? stations: true, addresses: true, - poi: true // points of interest + poi: true, // points of interest + stationLines: false // parse & expose lines of the station? }, opt) const f = profile.formatLocationFilter(opt.stations, opt.addresses, opt.poi) @@ -245,12 +247,14 @@ const createClient = (profile, request = _request) => { }) } - const station = (station) => { + const station = (station, opt = {}) => { if ('object' === typeof 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.') - const opt = {} + opt = Object.assign({ + stationLines: false // parse & expose lines of the station? + }, opt) return request(profile, opt, { meth: 'LocDetails', req: { @@ -282,6 +286,7 @@ const createClient = (profile, request = _request) => { distance: null, // maximum walking distance in meters poi: false, // return points of interest? stations: true, // return stations? + stationLines: false // parse & expose lines of the station? }, opt) return request(profile, opt, { diff --git a/p/db/example.js b/p/db/example.js index b456e927..9d7ef481 100644 --- a/p/db/example.js +++ b/p/db/example.js @@ -8,7 +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.arrivals('8011167', {duration: 10, stationLines: true}) // 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 190f8fa9..9397c65c 100644 --- a/p/insa/example.js +++ b/p/insa/example.js @@ -8,7 +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.arrivals('8010226', {duration: 10, stationLines: true}) // 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 65c2781b..62ff2f3c 100644 --- a/p/nahsh/example.js +++ b/p/nahsh/example.js @@ -8,7 +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.arrivals('8000199', {duration: 5, stationLines: true}) // 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 4c533023..ff6d5b40 100644 --- a/p/oebb/example.js +++ b/p/oebb/example.js @@ -8,7 +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.arrivals('8100002', {duration: 10, stationLines: true}) // client.locations('Salzburg', {results: 2}) // client.station('8100173') // Graz Hbf // client.nearby({ diff --git a/p/vbb/example.js b/p/vbb/example.js index af234c8a..6e249d23 100644 --- a/p/vbb/example.js +++ b/p/vbb/example.js @@ -8,9 +8,9 @@ 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.arrivals('900000013102', {duration: 10, stationLines: true}) // client.locations('Alexanderplatz', {results: 2}) -// client.station('900000042101') // Spichernstr +// client.station('900000042101', {stationLines: true}) // Spichernstr // client.nearby({ // type: 'location', // latitude: 52.5137344, diff --git a/parse/location.js b/parse/location.js index 83a528be..2e53f431 100644 --- a/parse/location.js +++ b/parse/location.js @@ -22,7 +22,11 @@ const parseLocation = (profile, opt, {lines}, l) => { if ('pCls' in l) station.products = profile.parseProducts(l.pCls) - if (Array.isArray(l.pRefL) && Array.isArray(lines)) { + if ( + opt.stationLines && + Array.isArray(l.pRefL) && + Array.isArray(lines) + ) { station.lines = [] for (let pRef of l.pRefL) { const line = lines[pRef]