mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
query arrivals ✨, docs 📝
This commit is contained in:
parent
1d5f4ff31c
commit
ac9819b1dd
8 changed files with 21 additions and 9 deletions
3
docs/arrivals.md
Normal file
3
docs/arrivals.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# `arrivals(station, [opt])`
|
||||
|
||||
Just like [`departures(station, [opt])`](departures.md), except that it gives arrival times instead of departure times.
|
|
@ -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
|
||||
|
|
21
index.js
21
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})
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -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})
|
||||
|
|
Loading…
Add table
Reference in a new issue