diff --git a/p/invg/example.js b/p/invg/example.js new file mode 100644 index 00000000..34e0b9fe --- /dev/null +++ b/p/invg/example.js @@ -0,0 +1,43 @@ +'use strict' + +const createClient = require('../..') +const cmtaProfile = require('.') + +const client = createClient(cmtaProfile, 'hafas-client-example') + +const ingolstadtHbf = '8000183' +const audiParkplatz = '84999' + +client.journeys(ingolstadtHbf, audiParkplatz, {results: 1}) +// .then(([journey]) => { +// const leg = journey.legs[0] +// return client.trip(leg.id, leg.line.name, {polyline: true}) +// }) +// .then(([journey]) => { +// return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) +// }) + +// client.departures(ingolstadtHbf, {duration: 5}) +// client.arrivals(ingolstadtHbf, {duration: 10, stationLines: true}) + +// client.locations('tillystr 1', {results: 2}) +// client.station(audiParkplatz) // Audi Parkplatz +// client.nearby({ +// type: 'location', +// latitude: 48.74453, +// longitude: 11.43733 +// }, {distance: 200}) + +// client.radar({ +// north: 48.74453, +// west: 11.42733, +// south: 48.73453, +// east: 11.43733 +// }, {results: 10}) + +// todo: `reachableFrom` with `Ingolstadt, Tillystraße 1` 48.745769 | 11.432814 + +.then((data) => { + console.log(require('util').inspect(data, {depth: null, colors: true})) +}) +.catch(console.error) diff --git a/p/invg/index.js b/p/invg/index.js new file mode 100644 index 00000000..39bc2535 --- /dev/null +++ b/p/invg/index.js @@ -0,0 +1,38 @@ +'use strict' + +const products = require('./products') + +const transformReqBody = (ctx, body) => { + body.client = { + type: 'IPH', + id: 'INVG', + name: 'invgPROD-APPSTORE-LIVE', + v: '1040000' + } + body.ver = '1.16' + body.auth = {type: 'AID', aid: 'GITvwi3BGOmTQ2a5'} + + return body +} + +const invgProfile = { + locale: 'de-DE', + timezone: 'Europe/Berlin', + endpoint: 'https://fpa.invg.de/bin/mgate.exe', + + // https://github.com/public-transport/hafas-client/issues/93#issuecomment-437594291 + // https://runkit.com/derhuerst/hafas-decrypt-encrypted-mac-salt + // https://gist.github.com/derhuerst/840c72ad19065f6c55657cf1bc7aa52a#file-config-txt-L23-L24 + salt: Buffer.from('ERxotxpwFT7uYRsI', 'utf8'), + addMicMac: true, + + transformReqBody, + + products, + + trip: true, + radar: true, + refreshJourney: true +} + +module.exports = invgProfile diff --git a/p/invg/products.js b/p/invg/products.js new file mode 100644 index 00000000..e8db7b78 --- /dev/null +++ b/p/invg/products.js @@ -0,0 +1,69 @@ +'use strict' + +module.exports = [ + // https://github.com/public-transport/hafas-client/issues/93#issuecomment-437868265 + { + id: 'bus', + mode: 'bus', + bitmasks: [1, 16], + name: 'Bus', + short: 'Bus', + default: true // the other `bus` has `false` + }, + { + id: 'express-train', + mode: 'train', + bitmasks: [2], + name: 'High-speed train', + short: 'Train', + default: false + }, + { + id: 'regional-train', + mode: 'train', + bitmasks: [4], + name: 'Regional train', + short: 'Train', + default: false + }, + { + id: 'local-train', + mode: 'train', + bitmasks: [8], + name: 'Nahverkehrszug', + short: 'Zug', + default: true + }, + { + id: 'ferry', + mode: 'watercraft', + bitmasks: [32], + name: 'Ferry', + short: 'Ferry', + default: false + }, + { + id: 'subway', + mode: 'train', + bitmasks: [64], + name: 'Subway', + short: 'Subway', + default: false + }, + { + id: 'tram', + mode: 'train', + bitmasks: [128], + name: 'Tram', + short: 'Tram', + default: false + }, + { + id: 'on-demand', + mode: 'bus', // todo: correct? + bitmasks: [256], + name: 'On-demand traffic', + short: 'on demand', + default: false + } +] diff --git a/p/invg/readme.md b/p/invg/readme.md new file mode 100644 index 00000000..064ab504 --- /dev/null +++ b/p/invg/readme.md @@ -0,0 +1,18 @@ +# INVG profile for `hafas-client` + +[*Ingolstädter Verkehrsgesellschaft (INVG)*](https://de.wikipedia.org/wiki/Ingolstädter_Verkehrsgesellschaft) is a public transportation provider serving [Ingolstadt, Germany](https://en.wikipedia.org/wiki/Ingolstadt). This profile adds *INVG*-specific customizations to `hafas-client`. + +## Usage + +```js +const createClient = require('hafas-client') +const invgProfile = require('hafas-client/p/invg') + +// create a client with INVG profile +const client = createClient(invgProfile, 'my-awesome-program') +``` + + +## Customisations + +- parses *INVG*-specific products diff --git a/readme.md b/readme.md index a9394fae..5d3406c5 100644 --- a/readme.md +++ b/readme.md @@ -219,6 +219,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code [*Nordhessischer Verkehrsverbund (NVV)*](https://en.wikipedia.org/wiki/Nordhessischer_Verkehrsverbund) ([Hesse](https://en.wikipedia.org/wiki/Hesse)) | - | [docs](p/nvv/readme.md) | [example code](p/nvv/example.js) | [src](p/nvv/index.js) *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) There are also libraries that use `hafas-client` and pass their own profile in: