mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
option to parse station lines, default off 💥, adapt docs 📝
This commit is contained in:
parent
471f075dea
commit
58f183506e
14 changed files with 38 additions and 14 deletions
|
@ -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`
|
||||
|
||||
|
|
|
@ -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?
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -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?
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
13
index.js
13
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, {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Reference in a new issue