From 3a9e548bcff496d540ae514bbe5f406ed946b407 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 3 Mar 2020 01:39:16 +0100 Subject: [PATCH] add RMV profile --- p/rmv/example.js | 48 ++++++++++++++++++++++++++ p/rmv/index.js | 29 ++++++++++++++++ p/rmv/products.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++ p/rmv/readme.md | 18 ++++++++++ readme.md | 1 + 5 files changed, 181 insertions(+) create mode 100644 p/rmv/example.js create mode 100644 p/rmv/index.js create mode 100644 p/rmv/products.js create mode 100644 p/rmv/readme.md diff --git a/p/rmv/example.js b/p/rmv/example.js new file mode 100644 index 00000000..aa334e6f --- /dev/null +++ b/p/rmv/example.js @@ -0,0 +1,48 @@ +'use strict' + +const createClient = require('../..') +const rmvProfile = require('.') + +const client = createClient(rmvProfile, 'hafas-client-example') + +const marburgHbf = '3010011' +const mainzGonsenheim = '3011332' +const offenbachLiebigstr = { + type: 'location', + id: '990148095', + address: 'Offenbach am Main, Liebigstraße 22', + latitude: 50.096326, longitude: 8.759979 +} + +client.journeys(marburgHbf, mainzGonsenheim, {results: 1}) +// client.departures(marburgHbf, {duration: 1}) +// client.arrivals(marburgHbf, {duration: 10, linesOfStops: true}) +// client.locations('wiesbaden igstadt', {results: 2}) +// client.stop(marburgHbf, {linesOfStops: true}) // Dammtor +// client.nearby(offenbachLiebigstr) +// client.radar({ +// north: 50.125, +// west: 8.661, +// south: 50.098, +// east: 8.71 +// }, {results: 10}) +// client.reachableFrom(offenbachLiebigstr, { +// 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) diff --git a/p/rmv/index.js b/p/rmv/index.js new file mode 100644 index 00000000..4cc2a0c0 --- /dev/null +++ b/p/rmv/index.js @@ -0,0 +1,29 @@ +'use strict' + +const products = require('./products') + +const transformReqBody = (ctx, body) => { + body.client = {type: 'WEB', id: 'RMV', name: 'webapp'} + body.ext = 'RMV.1' + body.ver = '1.18' + body.auth = {type: 'AID', aid: 'x0k4ZR33ICN9CWmj'} + + return body +} + +const hvvProfile = { + locale: 'de-DE', + timezone: 'Europe/Berlin', + endpoint: 'https://www.rmv.de/auskunft/bin/jp/mgate.exe', + + transformReqBody, + + products, + + trip: true, + radar: true, + refreshJourney: true, + reachableFrom: true +} + +module.exports = hvvProfile diff --git a/p/rmv/products.js b/p/rmv/products.js new file mode 100644 index 00000000..811cedc9 --- /dev/null +++ b/p/rmv/products.js @@ -0,0 +1,85 @@ +'use strict' + +module.exports = [ + { + id: 'express-train', + mode: 'train', + bitmasks: [1], + name: 'InterCityExpress/Fernzug', + short: 'ICE', + default: true + }, + { + id: 'long-distance-train', + mode: 'train', + bitmasks: [2], + name: 'EuroCity/InterCity/EuroNight/InterRegio', + short: 'EC/IC/EN/IR', + default: true + }, + { + id: 'regiona-train', + mode: 'train', + bitmasks: [4], + name: 'RegionalExpress/Regionalbahn', + short: 'RE/RB', + default: true + }, + { + id: 's-bahn', + mode: 'train', + bitmasks: [16], + name: 'S-Bahn', + short: 'S', + default: true + }, + { + id: 'u-bahn', + mode: 'train', + bitmasks: [32], + name: 'U-Bahn', + short: 'U', + default: true + }, + { + id: 'tram', + mode: 'train', + bitmasks: [64], + name: 'Straßenbahn', + short: 'Tram', + default: true + }, + { + id: 'bus', + mode: 'bus', + bitmasks: [128], + name: 'Bus', + short: 'Bus', + default: true + }, + { + id: 'watercraft', + mode: 'watercraft', + bitmasks: [256], + name: 'Schiff', + short: 'Schiff', + default: true + }, + { + id: 'ast', + mode: 'taxi', // todo: or `bus`? + bitmasks: [512], + name: 'Anruf-Sammel-Taxi', + short: 'AST', + default: true + }, + { + id: 'cable-car', + mode: 'gondola', + bitmasks: [1024], + name: 'Seilbahn', + short: 'Seilbahn', + default: true + } + // todo: remaining bitmask `1015` +] diff --git a/p/rmv/readme.md b/p/rmv/readme.md new file mode 100644 index 00000000..9ebe611d --- /dev/null +++ b/p/rmv/readme.md @@ -0,0 +1,18 @@ +# RMV profile for `hafas-client` + +[*Rhein-Main-Verkehrsverbund (RMV)*](https://en.wikipedia.org/wiki/Rhein-Main-Verkehrsverbund) is a public transport authority in [Hesse](https://en.wikipedia.org/wiki/Hesse)/[Rhineland-Palatinate](https://en.wikipedia.org/wiki/Rhineland-Palatinate). This profile adds *RMV*-specific customizations to `hafas-client`. + +## Usage + +```js +const createClient = require('hafas-client') +const rmvProfile = require('hafas-client/p/rmv') + +// create a client with RMV profile +const client = createClient(rmvProfile, 'my-awesome-program') +``` + + +## Customisations + +- parses *RMV*-specific products diff --git a/readme.md b/readme.md index 9ebeedb7..0e82c7c5 100644 --- a/readme.md +++ b/readme.md @@ -212,6 +212,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code [Österreichische Bundesbahnen (ÖBB)](https://en.wikipedia.org/wiki/Austrian_Federal_Railways) | [`oebb-hafas`](https://github.com/juliuste/oebb-hafas) | [docs](p/oebb/readme.md) | [example code](p/oebb/example.js) | [src](p/oebb/index.js) [Nahverkehr Sachsen-Anhalt (NASA)](https://de.wikipedia.org/wiki/Nahverkehrsservice_Sachsen-Anhalt)/[INSA](https://insa.de) | [`insa-hafas`](https://github.com/derhuerst/insa-hafas) | [docs](p/insa/readme.md) | [example code](p/insa/example.js) | [src](p/insa/index.js) [Nahverkehrsverbund Schleswig-Holstein (NAH.SH)](https://de.wikipedia.org/wiki/Nahverkehrsverbund_Schleswig-Holstein) | [`nahsh-hafas`](https://github.com/juliuste/nahsh-hafas) | [docs](p/nahsh/readme.md) | [example code](p/nahsh/example.js) | [src](p/nahsh/index.js) +[Rhein-Main-Verkehrsverbund (RMV)](https://en.wikipedia.org/wiki/Rhein-Main-Verkehrsverbund) | - | [docs](p/rmv/readme.md) | [example code](p/rmv/example.js) | [src](p/rmv/index.js) [Austin, Texas (CMTA/*CapMetro*)](https://en.wikipedia.org/wiki/Capital_Metropolitan_Transportation_Authority) | - | [docs](p/cmta/readme.md) | [example code](p/cmta/example.js) | [src](p/cmta/index.js) [*S-Bahn München*](https://en.wikipedia.org/wiki/Munich_S-Bahn) | - | [docs](p/sbahn-muenchen/readme.md) | [example code](p/sbahn-muenchen/example.js) | [src](p/sbahn-muenchen/index.js) *Saarfahrplan*/VGS ([Saarland](https://en.wikipedia.org/wiki/Saarland)) | - | [docs](p/saarfahrplan/readme.md) | [example code](p/saarfahrplan/example.js) | [src](p/saarfahrplan/index.js)