From 259fcd7ad5ac598ac9995894c226af7ec03b99a2 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 26 Nov 2020 13:54:16 +0100 Subject: [PATCH] add VRN profile --- p/vrn/example.js | 53 ++++++++++++++++++++++++++++++++++++++++ p/vrn/index.js | 44 ++++++++++++++++++++++++++++++++++ p/vrn/products.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++ p/vrn/readme.md | 18 ++++++++++++++ readme.md | 1 + 5 files changed, 177 insertions(+) create mode 100644 p/vrn/example.js create mode 100644 p/vrn/index.js create mode 100644 p/vrn/products.js create mode 100644 p/vrn/readme.md diff --git a/p/vrn/example.js b/p/vrn/example.js new file mode 100644 index 00000000..1393e6aa --- /dev/null +++ b/p/vrn/example.js @@ -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) diff --git a/p/vrn/index.js b/p/vrn/index.js new file mode 100644 index 00000000..20a1bd33 --- /dev/null +++ b/p/vrn/index.js @@ -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 diff --git a/p/vrn/products.js b/p/vrn/products.js new file mode 100644 index 00000000..f7324b8a --- /dev/null +++ b/p/vrn/products.js @@ -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, + }, +] diff --git a/p/vrn/readme.md b/p/vrn/readme.md new file mode 100644 index 00000000..84dae60e --- /dev/null +++ b/p/vrn/readme.md @@ -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 diff --git a/readme.md b/readme.md index 5a7f4ba8..7b4a12b7 100644 --- a/readme.md +++ b/readme.md @@ -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)