From 86ddf2c290f19448d1c8963e3472895bb8b6cf85 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 2 Mar 2020 23:16:45 +0100 Subject: [PATCH] add VMT profile --- p/vmt/example.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ p/vmt/index.js | 35 +++++++++++++++++++++++++++++++++++ p/vmt/products.js | 38 ++++++++++++++++++++++++++++++++++++++ p/vmt/readme.md | 17 +++++++++++++++++ readme.md | 1 + 5 files changed, 135 insertions(+) create mode 100644 p/vmt/example.js create mode 100644 p/vmt/index.js create mode 100644 p/vmt/products.js create mode 100644 p/vmt/readme.md diff --git a/p/vmt/example.js b/p/vmt/example.js new file mode 100644 index 00000000..fd566e64 --- /dev/null +++ b/p/vmt/example.js @@ -0,0 +1,44 @@ +'use strict' + +const createClient = require('../..') +const vmtProfile = require('.') + +const client = createClient(vmtProfile, 'hafas-client-example') + +const jena = '190014' +const gothaZOB = '167049' + +client.journeys(jena, gothaZOB, {results: 1}) +// client.departures(jena) +// client.arrivals(jena, {duration: 10, linesOfStops: true}) +// client.locations('ohrdruf', {results: 2}) +// client.stop(jena, {linesOfStops: true}) // Dammtor +// client.nearby({ +// type: 'location', +// latitude: 50.975615, +// longitude: 11.032374 +// }) +// client.reachableFrom({ +// type: 'location', +// id: '980348376', +// address: 'Erfurt, Grafengasse 12', +// latitude: 50.975993, longitude: 11.031553 +// }, { +// when: new Date('2020-03-04T10:00:00+01:00') +// }) + +// .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/vmt/index.js b/p/vmt/index.js new file mode 100644 index 00000000..8522bdf8 --- /dev/null +++ b/p/vmt/index.js @@ -0,0 +1,35 @@ +'use strict' + +const products = require('./products') + +const transformReqBody = (ctx, body) => { + body.client = {type: 'IPH', id: 'HAFAS', name: 'VMT', v: '2040100'} + body.ver = '1.18' + body.auth = {type: 'AID', aid: 't2h7u1e6r4i8n3g7e0n'} + + return body +} + +const hvvProfile = { + locale: 'de-DE', + timezone: 'Europe/Berlin', + // todo: what about `https://vmt.hafas.de/bin/mgate.exe`? + endpoint: 'https://vmt.hafas.de/bin/ticketing/mgate.exe', + + // https://runkit.com/derhuerst/hafas-decrypt-encrypted-mac-salt + // https://gist.github.com/derhuerst/b20adde9f614ceb6b2a8b9c7f4487da8#file-hafas-config-L31-L32 + salt: Buffer.from('7x8d3n2a5m1b3c6z', 'utf-8'), + addMicMac: true, + + transformReqBody, + + products, + + trip: true, + refreshJourney: true, + reachableFrom: true, + // fails with `CGI_READ_FAILED` + // radar: true, +} + +module.exports = hvvProfile diff --git a/p/vmt/products.js b/p/vmt/products.js new file mode 100644 index 00000000..2567dd30 --- /dev/null +++ b/p/vmt/products.js @@ -0,0 +1,38 @@ +'use strict' + +module.exports = [ // todo: what is `512`? + { + id: 'long-distance-train', + mode: 'train', + bitmasks: [1, 2, 4], + name: 'long-distance train', + short: 'ICE/IC/EC', + default: true + }, + { + id: 'regional-train', + mode: 'train', + // 8 is *not* always RB, 16 is *not* always RE! + bitmasks: [8, 16], + name: 'regional train', + short: 'RE/RB', + default: true + }, + { + id: 'tram', + mode: 'train', + bitmasks: [32], + name: 'tram', + short: 'tram', + default: true + }, + // todo: what are `64` & `128`? + { + id: 'bus', + mode: 'bus', + bitmasks: [256], + name: 'bus', + short: 'bus', + default: true + } +] diff --git a/p/vmt/readme.md b/p/vmt/readme.md new file mode 100644 index 00000000..07ed51fb --- /dev/null +++ b/p/vmt/readme.md @@ -0,0 +1,17 @@ +# VMT profile for `hafas-client` + +[*Verkehrsverbund Mittelthüringen (VMT)*](https://en.wikipedia.org/wiki/Verkehrsverbund_Mittelthüringen) is a major local transport authority in [Thuringia](https://en.wikipedia.org/wiki/Thuringia). This profile adds *VMT*-specific customizations to `hafas-client`. + +## Usage + +```js +const createClient = require('hafas-client') +const vmtProfile = require('hafas-client/p/vmt') + +// create a client with VMT profile +const client = createClient(vmtProfile, 'my-awesome-program') +``` + +## Customisations + +- parses *VMT*-specific products diff --git a/readme.md b/readme.md index 7eda85bf..78cf713a 100644 --- a/readme.md +++ b/readme.md @@ -224,6 +224,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code [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) [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) There are also libraries that use `hafas-client` and pass their own profile in: