add VRN profile

This commit is contained in:
Jannis R 2020-11-26 13:54:16 +01:00 committed by Jannis Redmann
parent 0e46be7237
commit 259fcd7ad5
5 changed files with 177 additions and 0 deletions

53
p/vrn/example.js Normal file
View file

@ -0,0 +1,53 @@
'use strict'
const createClient = require('../..')
const hvvProfile = require('.')
const client = createClient(hvvProfile, 'hafas-client-example')
const ludwigshafen = '8000236'
const meckesheim = '8003932'
// client.journeys(ludwigshafen, meckesheim, {results: 1, polylines: true})
// .then(({journeys}) => {
// const leg = journeys[0].legs[0]
// return client.trip(leg.tripId, leg.line.name, {polyline: true})
// })
// .then(({journeys}) => {
// const [journey] = journeys
// return client.refreshJourney(journeys[0].refreshToken, {
// stopovers: true, remarks: true
// })
// })
// client.departures(ludwigshafen, {duration: 1})
// client.arrivals(ludwigshafen, {duration: 10, linesOfStops: true})
// client.locations('meckesheim', {results: 2})
// client.stop(ludwigshafen, {linesOfStops: true}) // Dammtor
// client.nearby({
// type: 'location',
// latitude: 53.554422,
// longitude: 9.977934
// }, {distance: 60})
// client.reachableFrom({
// type: 'location',
// id: '980787337',
// address: 'Ludwigshafen am Rhein - Mitte, Pestalozzistraße 2',
// latitude: 49.474336, longitude: 8.441779,
// }, {
// when: new Date('2020-12-01T10:00:00+01:00'),
// maxDuration: 8,
// })
// client.radar({
// north: 49.4940,
// west: 8.4560,
// south: 49.4774,
// east: 8.4834,
// }, {results: 10})
.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
})
.catch(console.error)

44
p/vrn/index.js Normal file
View file

@ -0,0 +1,44 @@
'use strict'
const products = require('./products')
const transformReqBody = (ctx, body) => {
body.client = {type: 'IPH', id: 'DB-REGIO-VRN', name: 'VRN', v: '6000400'}
body.ext = 'DB.R19.04.a'
body.ver = '1.24'
body.auth = {type: 'AID', aid: 'p091VRNZz79KtUz5'}
return body
}
const formatRefreshJourneyReq = ({opt}, refreshToken) => {
return {
meth: 'Reconstruction',
req: {
outReconL: [{ctx: refreshToken}],
},
}
}
module.exports = formatRefreshJourneyReq
const hvvProfile = {
locale: 'de-DE',
timezone: 'Europe/Berlin',
endpoint: 'https://vrn.hafas.de/bin/mgate.exe',
transformReqBody,
products,
trip: true,
radar: true,
reachableFrom: true,
refreshJourney: true,
formatRefreshJourneyReq,
departuresGetPasslist: false, // `departures()`: support for `getPasslist`?
departuresStbFltrEquiv: false, // `departures()`: support for `stbFltrEquiv`?
}
module.exports = hvvProfile

61
p/vrn/products.js Normal file
View file

@ -0,0 +1,61 @@
'use strict'
module.exports = [
// todo: what is `64`?
{
id: 'regional-train',
mode: 'train',
bitmasks: [8],
name: 'regional train',
short: 'RE/RB',
default: true,
},
{
id: 'urban-train',
mode: 'train',
bitmasks: [16],
name: 'urban train',
short: 'S',
default: true,
},
{
id: 'subway',
mode: 'train',
bitmasks: [128],
name: 'subway',
short: 'U',
default: true,
},
{
id: 'tram',
mode: 'train',
bitmasks: [256],
name: 'tram',
short: 'Tram',
default: true,
},
{
id: 'bus',
mode: 'bus',
bitmasks: [32],
name: 'Bus',
short: 'Bus',
default: true,
},
{
id: 'dial-a-ride',
mode: 'taxi',
bitmasks: [512],
name: 'dial-a-ride',
short: 'taxi',
default: true,
},
{
id: 'long-distance-train',
mode: 'train',
bitmasks: [1, 2, 4],
name: 'long-distance train',
short: 'ICE/IC/EC/EN',
default: false,
},
]

18
p/vrn/readme.md Normal file
View file

@ -0,0 +1,18 @@
# VRN profile for `hafas-client`
[*Verkehrsverbund Rhein-Neckar (VRN)*](https://en.wikipedia.org/wiki/Verkehrsverbund_Rhein-Neckar) is a public transport network in south-west Germany. This profile adds *VRN*-specific customizations to `hafas-client`.
## Usage
```js
const createClient = require('hafas-client')
const vrnProfile = require('hafas-client/p/vrn')
// create a client with VRN profile
const client = createClient(vrnProfile, 'my-awesome-program')
```
## Customisations
- parses *VRN*-specific products

View file

@ -226,6 +226,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code
[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)
[Verkehrsverbund Rhein-Neckar (VRN)](https://en.wikipedia.org/wiki/Verkehrsverbund_Rhein-Neckar) | - | [docs](p/vrn/readme.md) | [example code](p/vrn/example.js) | [src](p/vrn/index.js)
[Rostocker Straßenbahn AG (RSAG)](https://de.wikipedia.org/wiki/Rostocker_Straßenbahn_AG) | - | [docs](p/rsag/readme.md) | [example code](p/rsag/example.js) | [src](p/rsag/index.js)
[Verkehrsverbund Mittelthüringen (VMT)](https://en.wikipedia.org/wiki/Verkehrsverbund_Mittelthüringen) | - | [docs](p/vmt/readme.md) | [example code](p/vmt/example.js) | [src](p/vmt/index.js)
[Salzburg public transport (SVV)](https://de.wikipedia.org/wiki/Salzburger_Verkehrsverbund) | - | [docs](p/svv/readme.md) | [example code](p/svv/example.js) | [src](p/svv/index.js)