mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
add VBN profile
This commit is contained in:
parent
c2b15fab50
commit
682f9f948d
6 changed files with 180 additions and 273 deletions
48
p/vbn/example.js
Normal file
48
p/vbn/example.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
'use strict'
|
||||
|
||||
const createClient = require('../..')
|
||||
const vbnProfile = require('.')
|
||||
|
||||
const client = createClient(vbnProfile, 'hafas-client-example')
|
||||
|
||||
const bremerhavenHbf = '9014418'
|
||||
const verden = '9093627'
|
||||
const bremenRutenstr = {
|
||||
type: 'location',
|
||||
id: '990025693',
|
||||
address: 'Bremen Rutenstraße 1',
|
||||
latitude: 53.074165, longitude: 8.8184
|
||||
}
|
||||
|
||||
client.journeys(bremerhavenHbf, verden, {results: 1})
|
||||
// client.departures(bremerhavenHbf, {duration: 1})
|
||||
// client.arrivals(bremerhavenHbf, {duration: 10, linesOfStops: true})
|
||||
// client.locations('oldenburg', {results: 2})
|
||||
// client.stop(bremerhavenHbf, {linesOfStops: true})
|
||||
// client.nearby(bremenRutenstr)
|
||||
// client.radar({
|
||||
// north: 53.087,
|
||||
// west: 8.777,
|
||||
// south: 53.072,
|
||||
// east: 8.835
|
||||
// }, {results: 10})
|
||||
// client.reachableFrom(bremenRutenstr, {
|
||||
// when: new Date('2020-03-03T10:00:00+01:00'),
|
||||
// maxDuration: 10
|
||||
// })
|
||||
|
||||
// .then(({journeys}) => {
|
||||
// const [journey] = journeys
|
||||
// const leg = journey.legs[0]
|
||||
// return client.trip(leg.tripId, leg.line.name, {polyline: true})
|
||||
// })
|
||||
|
||||
// .then(({journeys}) => {
|
||||
// const [journey] = journeys
|
||||
// return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true})
|
||||
// })
|
||||
|
||||
.then((data) => {
|
||||
console.log(require('util').inspect(data, {depth: null, colors: true}))
|
||||
})
|
||||
.catch(console.error)
|
37
p/vbn/index.js
Normal file
37
p/vbn/index.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
'use strict'
|
||||
|
||||
const products = require('./products')
|
||||
|
||||
const transformReqBody = (ctx, body) => {
|
||||
body.client = {type: 'IPH', id: 'VBN', name: 'vbn', v: '6000000'}
|
||||
body.ver = '1.27'
|
||||
body.auth = {type: 'AID', aid: 'kaoxIXLn03zCr2KR'}
|
||||
|
||||
return body
|
||||
}
|
||||
|
||||
const insaProfile = {
|
||||
locale: 'de-DE',
|
||||
timezone: 'Europe/Berlin',
|
||||
endpoint: 'https://fahrplaner.vbn.de/bin/mgate.exe',
|
||||
|
||||
// https://runkit.com/derhuerst/hafas-decrypt-encrypted-mac-salt
|
||||
// https://gist.github.com/derhuerst/fd2f81a597bde66cb1f689006d574d7f#file-config-txt-L22-L23
|
||||
salt: Buffer.from('SP31mBufSyCLmNxp', 'utf-8'),
|
||||
addMicMac: true,
|
||||
|
||||
transformReqBody,
|
||||
|
||||
products: products,
|
||||
|
||||
trip: true,
|
||||
radar: true,
|
||||
reachableFrom: true,
|
||||
|
||||
// todo: these fail with ver >= 1.21, see #164
|
||||
refreshJourney: false,
|
||||
departuresGetPasslist: false,
|
||||
departuresStbFltrEquiv: false,
|
||||
}
|
||||
|
||||
module.exports = insaProfile;
|
76
p/vbn/products.js
Normal file
76
p/vbn/products.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
'use strict'
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
id: 'express-train',
|
||||
mode: 'train',
|
||||
bitmasks: [1],
|
||||
name: 'InterCityExpress',
|
||||
short: 'ICE',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'national-train',
|
||||
mode: 'train',
|
||||
bitmasks: [2, 4],
|
||||
name: 'InterCity, EuroCity, CityNightLine, InterRegio',
|
||||
short: 'IC/EC/CNL/IR',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'local-train',
|
||||
mode: 'train',
|
||||
bitmasks: [8],
|
||||
name: 'Nahverkehr',
|
||||
short: 'Nahv.',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'suburban',
|
||||
mode: 'train',
|
||||
bitmasks: [16],
|
||||
name: 'S-Bahn',
|
||||
short: 'S',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'bus',
|
||||
mode: 'bus',
|
||||
bitmasks: [32],
|
||||
name: 'Bus',
|
||||
short: 'Bus',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'watercraft',
|
||||
mode: 'watercraft',
|
||||
bitmasks: [64],
|
||||
name: 'Schiff',
|
||||
short: 'Schiff',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'subway',
|
||||
mode: 'train',
|
||||
bitmasks: [128],
|
||||
name: 'U-Bahn',
|
||||
short: 'U',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'tram',
|
||||
mode: 'train',
|
||||
bitmasks: [256],
|
||||
name: 'Tram',
|
||||
short: 'Tram',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'dial-a-ride',
|
||||
mode: 'taxi', // todo: or `bus`?
|
||||
bitmasks: [256],
|
||||
name: 'Anrufverkehr',
|
||||
short: 'AST',
|
||||
default: true
|
||||
}
|
||||
]
|
18
p/vbn/readme.md
Normal file
18
p/vbn/readme.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# VBN profile for `hafas-client`
|
||||
|
||||
The [*Verkehrsverbund Bremen/Niedersachsen (VBN)*](https://de.wikipedia.org/wiki/Verkehrsverbund_Bremen/Niedersachsen) is a public transportation provider for [Lower Saxony](https://en.wikipedia.org/wiki/Lower_Saxony). This profile adds *VBN*-specific customizations to `hafas-client`.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const createClient = require('hafas-client')
|
||||
const vbnProfile = require('hafas-client/p/vbn')
|
||||
|
||||
// create a client with VBN profile
|
||||
const client = createClient(vbnProfile, 'my-awesome-program')
|
||||
```
|
||||
|
||||
|
||||
## Customisations
|
||||
|
||||
- parses *VBN*-specific products (such as *Anrufverkehr*)
|
|
@ -221,6 +221,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code
|
|||
*DB Busradar NRW* ([DB Regio Bus](https://en.wikipedia.org/wiki/DB_Regio#Bus_division_(DB_Regio_Bus))) | - | [docs](p/db-busradar-nrw/readme.md) | [example code](p/db-busradar-nrw/example.js) | [src](p/db-busradar-nrw/index.js)
|
||||
[Verkehrsverbund Süd-Niedersachsen (VSN)](https://de.wikipedia.org/wiki/Verkehrsverbund_S%C3%BCd-Niedersachsen) | - | [docs](p/vsn/readme.md) | [example code](p/vsn/example.js) | [src](p/vsn/index.js)
|
||||
[Ingolstädter Verkehrsgesellschaft (INVG)](https://de.wikipedia.org/wiki/Ingolstädter_Verkehrsgesellschaft) | - | [docs](p/invg/readme.md) | [example code](p/invg/example.js) | [src](p/invg/index.js)
|
||||
[Verkehrsverbund Bremen/Niedersachsen (VBN)](https://de.wikipedia.org/wiki/Verkehrsverbund_Bremen/Niedersachsen) | - | [docs](p/vbn/readme.md) | [example code](p/vbn/example.js) | [src](p/vbn/index.js)
|
||||
|
||||
There are also libraries that use `hafas-client` and pass their own profile in:
|
||||
|
||||
|
|
273
test/e2e/vbn.js
273
test/e2e/vbn.js
|
@ -1,273 +0,0 @@
|
|||
'use strict'
|
||||
|
||||
const tapePromise = require('tape-promise').default
|
||||
const tape = require('tape')
|
||||
const isRoughlyEqual = require('is-roughly-equal')
|
||||
|
||||
const {createWhen} = require('./lib/util')
|
||||
const createClient = require('../..')
|
||||
const vbnProfile = require('../../p/vbn')
|
||||
const products = require('../../p/vbn/products')
|
||||
const createValidate = require('./lib/validate-fptf-with')
|
||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
||||
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||
const testRefreshJourney = require('./lib/refresh-journey')
|
||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
||||
const testDepartures = require('./lib/departures')
|
||||
const testArrivals = require('./lib/arrivals')
|
||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
||||
|
||||
const when = createWhen('Europe/Berlin', 'de-DE')
|
||||
|
||||
const cfg = {
|
||||
when,
|
||||
stationCoordsOptional: false,
|
||||
products,
|
||||
minLatitude: 52.559311,
|
||||
maxLatitude: 53.948075,
|
||||
minLongitude: 7.622917,
|
||||
maxLongitude: 9.984605
|
||||
}
|
||||
|
||||
const validate = createValidate(cfg, {})
|
||||
|
||||
const test = tapePromise(tape)
|
||||
const client = createClient(vbnProfile, 'public-transport/hafas-client:test')
|
||||
|
||||
const bremenHbf = '8000050'
|
||||
const bremerhavenHbf = '8000051'
|
||||
|
||||
test.only('journeys – Bremen Hbf to Bremerhaven Hbf', async (t) => {
|
||||
const res = await client.journeys(bremenHbf, bremerhavenHbf, {
|
||||
results: 4,
|
||||
departure: when,
|
||||
stopovers: true
|
||||
})
|
||||
|
||||
await testJourneysStationToStation({
|
||||
test: t,
|
||||
res,
|
||||
validate,
|
||||
fromId: bremenHbf,
|
||||
toId: bremerhavenHbf
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
// todo: journeys, only one product
|
||||
|
||||
test.skip('journeys – fails with no product', (t) => {
|
||||
journeysFailsWithNoProduct({
|
||||
test: t,
|
||||
fetchJourneys: client.journeys,
|
||||
fromId: bremenHbf,
|
||||
toId: bremerhavenHbf,
|
||||
when,
|
||||
products
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test.skip('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', async (t) => {
|
||||
const sternStr = {
|
||||
type: 'location',
|
||||
address: 'Magdeburg - Altenstadt, Sternstraße 10',
|
||||
latitude: 52.118414,
|
||||
longitude: 11.422332
|
||||
}
|
||||
|
||||
const res = await client.journeys(bremenHbf, sternStr, {
|
||||
results: 3,
|
||||
departure: when
|
||||
})
|
||||
|
||||
await testJourneysStationToAddress({
|
||||
test: t,
|
||||
res,
|
||||
validate,
|
||||
fromId: bremenHbf,
|
||||
to: sternStr
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test.skip('Magdeburg Hbf to Kloster Unser Lieben Frauen', async (t) => {
|
||||
const kloster = {
|
||||
type: 'location',
|
||||
id: '970012223',
|
||||
poi: true,
|
||||
name: 'Magdeburg, Kloster Unser Lieben Frauen (Denkmal)',
|
||||
latitude: 52.127601,
|
||||
longitude: 11.636437
|
||||
}
|
||||
const res = await client.journeys(bremenHbf, kloster, {
|
||||
results: 3,
|
||||
departure: when
|
||||
})
|
||||
|
||||
await testJourneysStationToPoi({
|
||||
test: t,
|
||||
res,
|
||||
validate,
|
||||
fromId: bremenHbf,
|
||||
to: kloster
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test.skip('journeys: via works – with detour', async (t) => {
|
||||
// Going from Magdeburg, Hasselbachplatz (Sternstr.) (Tram/Bus) to Stendal
|
||||
// via Dessau without detour is currently impossible. We check if the routing
|
||||
// engine computes a detour.
|
||||
const res = await client.journeys(hasselbachplatzSternstrasse, stendal, {
|
||||
via: dessau,
|
||||
results: 1,
|
||||
departure: when,
|
||||
stopovers: true
|
||||
})
|
||||
|
||||
await testJourneysWithDetour({
|
||||
test: t,
|
||||
res,
|
||||
validate,
|
||||
detourIds: [dessau]
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
// todo: without detour
|
||||
|
||||
test.skip('earlier/later journeys', async (t) => {
|
||||
await testEarlierLaterJourneys({
|
||||
test: t,
|
||||
fetchJourneys: client.journeys,
|
||||
validate,
|
||||
fromId: bremenHbf,
|
||||
toId: bremerhavenHbf,
|
||||
when
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test.skip('refreshJourney', async (t) => {
|
||||
await testRefreshJourney({
|
||||
test: t,
|
||||
fetchJourneys: client.journeys,
|
||||
refreshJourney: client.refreshJourney,
|
||||
validate,
|
||||
fromId: bremenHbf,
|
||||
toId: bremerhavenHbf,
|
||||
when
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test.skip('trip details', async (t) => {
|
||||
const res = await client.journeys(bremenHbf, bremerhavenHbf, {
|
||||
results: 1, departure: when
|
||||
})
|
||||
|
||||
const p = res.journeys[0].legs[0]
|
||||
t.ok(p.tripId, 'precondition failed')
|
||||
t.ok(p.line.name, 'precondition failed')
|
||||
const trip = await client.trip(p.tripId, p.line.name, {when})
|
||||
|
||||
validate(t, trip, 'trip', 'trip')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test.skip('departures at Magdeburg Leiterstr.', async (t) => {
|
||||
const departures = await client.departures(leiterstr, {
|
||||
duration: 5, when,
|
||||
stopovers: true
|
||||
})
|
||||
|
||||
await testDepartures({
|
||||
test: t,
|
||||
departures,
|
||||
validate,
|
||||
id: leiterstr
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test.skip('departures with station object', async (t) => {
|
||||
const deps = await client.departures({
|
||||
type: 'station',
|
||||
id: bremenHbf,
|
||||
name: 'Magdeburg Hbf',
|
||||
location: {
|
||||
type: 'location',
|
||||
latitude: 1.23,
|
||||
longitude: 2.34
|
||||
}
|
||||
}, {when})
|
||||
|
||||
validate(t, deps, 'departures', 'departures')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test.skip('arrivals at Magdeburg Leiterstr.', async (t) => {
|
||||
const arrivals = await client.arrivals(leiterstr, {
|
||||
duration: 5, when,
|
||||
stopovers: true
|
||||
})
|
||||
|
||||
await testArrivals({
|
||||
test: t,
|
||||
arrivals,
|
||||
validate,
|
||||
id: leiterstr
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
// todo: nearby
|
||||
|
||||
test.skip('locations named Magdeburg', async (t) => {
|
||||
const locations = await client.locations('Magdeburg', {
|
||||
results: 20
|
||||
})
|
||||
|
||||
validate(t, locations, 'locations', 'locations')
|
||||
t.ok(locations.length <= 20)
|
||||
|
||||
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
|
||||
t.ok(locations.find(s => s.poi)) // POIs
|
||||
t.ok(locations.some((l) => {
|
||||
return l.station && l.station.id === bremenHbf || l.id === bremenHbf
|
||||
}))
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test.skip('station Magdeburg-Buckau', async (t) => {
|
||||
const s = await client.stop(bremerhavenHbf)
|
||||
|
||||
validate(t, s, ['stop', 'station'], 'station')
|
||||
t.equal(s.id, bremerhavenHbf)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test.skip('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
north: 52.148364,
|
||||
west: 11.600826,
|
||||
south: 52.108486,
|
||||
east: 11.651451
|
||||
}, {
|
||||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
|
||||
const customCfg = Object.assign({}, cfg, {
|
||||
stationCoordsOptional: true, // see #28
|
||||
})
|
||||
const validate = createValidate(customCfg, {})
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
|
||||
t.end()
|
||||
})
|
Loading…
Add table
Reference in a new issue