mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
merge next into tests-rewrite
This commit is contained in:
commit
b419477a7d
17 changed files with 44 additions and 23 deletions
|
@ -4,7 +4,7 @@
|
|||
- [`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
|
||||
- [`locations(query, [opt])`](locations.md) – find stations, POIs and addresses
|
||||
- [`location(id)`](location.md) – get details about a location
|
||||
- [`station(id)`](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,9 +1,9 @@
|
|||
# `location(station)`
|
||||
# `station(id)`
|
||||
|
||||
`station` must be in one of these formats:
|
||||
`id` must be in one of these formats:
|
||||
|
||||
```js
|
||||
// a station ID, in a format compatible to the profile you use
|
||||
// a station ID, in a format compatible with the profile you use
|
||||
'900000123456'
|
||||
|
||||
// an FPTF `station` object
|
||||
|
@ -29,7 +29,7 @@ const vbbProfile = require('hafas-client/p/vbb')
|
|||
|
||||
const client = createClient(vbbProfile)
|
||||
|
||||
client.location('900000042101') // U Spichernstr.
|
||||
client.station('900000042101') // U Spichernstr.
|
||||
.then(console.log)
|
||||
.catch(console.error)
|
||||
```
|
4
index.js
4
index.js
|
@ -221,7 +221,7 @@ const createClient = (profile, request = _request) => {
|
|||
})
|
||||
}
|
||||
|
||||
const location = (station) => {
|
||||
const station = (station) => {
|
||||
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.')
|
||||
|
@ -368,7 +368,7 @@ const createClient = (profile, request = _request) => {
|
|||
})
|
||||
}
|
||||
|
||||
const client = {departures, journeys, locations, location, nearby}
|
||||
const client = {departures, journeys, locations, station, nearby}
|
||||
if (profile.journeyLeg) client.journeyLeg = journeyLeg
|
||||
if (profile.radar) client.radar = radar
|
||||
Object.defineProperty(client, 'profile', {value: profile})
|
||||
|
|
|
@ -20,6 +20,7 @@ const request = (profile, data) => {
|
|||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Accept': 'application/json',
|
||||
'user-agent': 'https://github.com/public-transport/hafas-client'
|
||||
},
|
||||
query: {}
|
||||
|
|
|
@ -10,7 +10,7 @@ client.journeys('8011167', '8000261', {results: 1, tickets: true})
|
|||
// client.departures('8011167', {duration: 1})
|
||||
// client.locations('Berlin Jungfernheide')
|
||||
// client.locations('Atze Musiktheater', {poi: true, addressses: false, fuzzy: false})
|
||||
// client.location('8000309') // Regensburg Hbf
|
||||
// client.station('8000309') // Regensburg Hbf
|
||||
// client.nearby(52.4751309, 13.3656537, {results: 1})
|
||||
|
||||
.then((data) => {
|
||||
|
|
|
@ -10,7 +10,7 @@ client.journeys('008010226', '008013456', {results: 1})
|
|||
// client.departures('008010226', { duration: 5 })
|
||||
// client.locations('Magdeburg Hbf', {results: 2})
|
||||
// client.locations('Kunstmuseum Kloster Unser Lieben Frauen Magdeburg', {results: 2})
|
||||
// client.location('008010226') // Magdeburg-Neustadt
|
||||
// client.station('008010226') // Magdeburg-Neustadt
|
||||
// client.nearby({
|
||||
// type: 'location',
|
||||
// latitude: 52.148842,
|
||||
|
|
|
@ -10,7 +10,7 @@ client.journeys('8000103', '8000199', {results: 10, tickets: true})
|
|||
// client.departures('8000199', {duration: 10})
|
||||
// client.journeyLeg('1|30161|5|100|14032018', 'Bus 52')
|
||||
// client.locations('Schleswig', {results: 1})
|
||||
// client.location('706990') // Kiel Holunderbusch
|
||||
// client.station('706990') // Kiel Holunderbusch
|
||||
// client.nearby({type: 'location', latitude: 54.295691, longitude: 10.116424}, {distance: 60})
|
||||
// client.radar(54.4, 10.0, 54.2, 10.2, {results: 10})
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ const client = createClient(oebbProfile)
|
|||
client.journeys('1291501', '8100002', {results: 1})
|
||||
// client.departures('8100002', {duration: 1})
|
||||
// client.locations('Salzburg', {results: 2})
|
||||
// client.location('8100173') // Graz Hbf
|
||||
// client.station('8100173') // Graz Hbf
|
||||
// client.nearby(47.812851, 13.045604, {distance: 60})
|
||||
// client.radar({
|
||||
// north: 47.827203,
|
||||
|
|
|
@ -9,7 +9,7 @@ const client = createClient(vbbProfile)
|
|||
client.journeys('900000003201', '900000024101', {results: 1, polylines: true})
|
||||
// client.departures('900000013102', {duration: 1})
|
||||
// client.locations('Alexanderplatz', {results: 2})
|
||||
// client.location('900000042101') // Spichernstr
|
||||
// client.station('900000042101') // Spichernstr
|
||||
// client.nearby(52.5137344, 13.4744798, {distance: 60})
|
||||
// client.radar({
|
||||
// north: 52.52411,
|
||||
|
|
|
@ -30,6 +30,8 @@ const createParseDeparture = (profile, stations, lines, remarks) => {
|
|||
res.delay = Math.round((realtime - planned) / 1000)
|
||||
} else res.delay = null
|
||||
|
||||
// todo: DRY with parseStopover
|
||||
// todo: DRY with parseJourneyLeg
|
||||
if (d.stbStop.aCncl || d.stbStop.dCncl) {
|
||||
res.cancelled = true
|
||||
Object.defineProperty(res, 'canceled', {value: true})
|
||||
|
|
|
@ -23,6 +23,8 @@ const createParseJourneyLeg = (profile, stations, lines, remarks, polylines) =>
|
|||
arrival: arr.toISO()
|
||||
}
|
||||
|
||||
// todo: DRY with parseDeparture
|
||||
// todo: DRY with parseStopover
|
||||
if (pt.dep.dTimeR && pt.dep.dTimeS) {
|
||||
const realtime = profile.parseDateTime(profile, j.date, pt.dep.dTimeR)
|
||||
const planned = profile.parseDateTime(profile, j.date, pt.dep.dTimeS)
|
||||
|
|
|
@ -7,16 +7,32 @@ const createParseStopover = (profile, stations, lines, remarks, date) => {
|
|||
const res = {
|
||||
station: stations[parseInt(st.locX)] || null,
|
||||
arrival: null,
|
||||
departure: null
|
||||
arrivalDelay: null,
|
||||
departure: null,
|
||||
departureDelay: null
|
||||
}
|
||||
|
||||
// todo: DRY with parseDeparture
|
||||
// todo: DRY with parseJourneyLeg
|
||||
if (st.aTimeR || st.aTimeS) {
|
||||
const arr = profile.parseDateTime(profile, date, st.aTimeR || st.aTimeS)
|
||||
res.arrival = arr.toISO()
|
||||
}
|
||||
if (st.aTimeR && st.aTimeS) {
|
||||
const realtime = profile.parseDateTime(profile, date, st.aTimeR)
|
||||
const planned = profile.parseDateTime(profile, date, st.aTimeS)
|
||||
res.arrivalDelay = Math.round((realtime - planned) / 1000)
|
||||
}
|
||||
|
||||
if (st.dTimeR || st.dTimeS) {
|
||||
const dep = profile.parseDateTime(profile, date, st.dTimeR || st.dTimeS)
|
||||
res.departure = dep.toISO()
|
||||
}
|
||||
if (st.dTimeR && st.dTimeS) {
|
||||
const realtime = profile.parseDateTime(profile, date, st.dTimeR)
|
||||
const planned = profile.parseDateTime(profile, date, st.dTimeS)
|
||||
res.departureDelay = Math.round((realtime - planned) / 1000)
|
||||
}
|
||||
|
||||
// mark stations the train passes without stopping
|
||||
if(st.dInS === false && st.aOutS === false) res.passBy = true
|
||||
|
|
|
@ -278,8 +278,8 @@ test('locations named Jungfernheide', co(function* (t) {
|
|||
t.end()
|
||||
}))
|
||||
|
||||
test('location', co(function* (t) {
|
||||
const s = yield client.location(regensburgHbf)
|
||||
test('station', co(function* (t) {
|
||||
const s = yield client.station(regensburgHbf)
|
||||
|
||||
validate(t, s, 'station', 'station')
|
||||
t.equal(s.id, regensburgHbf)
|
||||
|
|
|
@ -217,8 +217,8 @@ test('locations named Magdeburg', co(function*(t) {
|
|||
t.end()
|
||||
}))
|
||||
|
||||
test('location Magdeburg-Buckau', co(function* (t) {
|
||||
const s = yield client.location(magdeburgBuckau)
|
||||
test('station Magdeburg-Buckau', co(function* (t) {
|
||||
const s = yield client.station(magdeburgBuckau)
|
||||
|
||||
validate(t, s, 'station', 'station')
|
||||
t.equal(s.id, magdeburgBuckau)
|
||||
|
|
|
@ -267,8 +267,8 @@ test('locations named Kiel', co(function* (t) {
|
|||
t.end()
|
||||
}))
|
||||
|
||||
test('location', co(function* (t) {
|
||||
const s = yield client.location(kielHbf)
|
||||
test('station', co(function* (t) {
|
||||
const s = yield client.station(kielHbf)
|
||||
|
||||
validate(t, s, 'station', 'station')
|
||||
t.equal(s.id, kielHbf)
|
||||
|
|
|
@ -303,8 +303,8 @@ test('locations named Salzburg', co(function* (t) {
|
|||
t.end()
|
||||
}))
|
||||
|
||||
test('location', co(function* (t) {
|
||||
const loc = yield client.location(wienRenngasse)
|
||||
test('station', co(function* (t) {
|
||||
const loc = yield client.station(wienRenngasse)
|
||||
|
||||
// todo: find a way to always get products from the API
|
||||
// todo: cfg.stationProductsOptional option
|
||||
|
|
|
@ -342,8 +342,8 @@ test('locations', co(function* (t) {
|
|||
t.end()
|
||||
}))
|
||||
|
||||
test('location', co(function* (t) {
|
||||
const s = yield client.location(spichernstr)
|
||||
test('station', co(function* (t) {
|
||||
const s = yield client.station(spichernstr)
|
||||
|
||||
validate(t, s, 'station', 'station')
|
||||
t.equal(s.id, spichernstr)
|
||||
|
|
Loading…
Add table
Reference in a new issue