Skip to content

Commit

Permalink
option to parse station lines, default off 💥, adapt docs 📝
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Jun 28, 2018
1 parent 471f075 commit 58f1835
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
3 changes: 2 additions & 1 deletion docs/departures.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
```

Expand Down
1 change: 1 addition & 0 deletions docs/locations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
```

Expand Down
4 changes: 4 additions & 0 deletions docs/migrating-to-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions docs/nearby.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion docs/station.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `station(id)`
# `station(id, [opt])`

`id` must be in one of these formats:

Expand All @@ -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):
Expand Down
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand All @@ -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: {
Expand Down Expand Up @@ -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, {
Expand Down
2 changes: 1 addition & 1 deletion p/db/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion p/insa/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion p/nahsh/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion p/oebb/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions p/vbb/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion parse/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 58f1835

Please sign in to comment.