diff --git a/p/nvv/example.js b/p/nvv/example.js new file mode 100644 index 00000000..dcd0d4aa --- /dev/null +++ b/p/nvv/example.js @@ -0,0 +1,49 @@ +'use strict' + +const createClient = require('../..') +const nvvProfile = require('.') + +const client = createClient(nvvProfile, 'hafas-client-example') + +// Scheidemannplatz to Auestadion +client.journeys('2200073', '2200042', {results: 1, polylines: true}) +// .then(({journeys}) => { +// const [journey] = journeys +// const leg = journey.legs.find(l => !!l.line) +// return client.trip(leg.tripId, leg.line.name, {polyline: true}) +// }) +// .then(({journeys}) => { +// const [journey] = journeys +// return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) +// }) + +// client.departures('2200005', {duration: 1, stopovers: true}) +// client.arrivals('2200005', {duration: 10, linesOfStops: true}) +// client.locations('kirchweg', {results: 2}) +// client.stop('2200005', {linesOfStops: true}) // Kassel Kirchweg +// client.nearby({ +// type: 'location', +// latitude: 51.313, +// longitude: 9.4654 +// }, {distance: 400}) +// client.radar({ +// north: 51.320153, +// west: 9.458359, +// south: 51.304304, +// east: 9.493672 +// }, {results: 10}) +// client.reachableFrom({ +// type: 'location', +// id: '990100251', +// address: 'Kassel, Heckerstraße 2', +// latitude: 51.308108, +// longitude: 9.475152 +// }, { +// when: new Date('2019-04-02T10:00:00+0200'), +// maxDuration: 10 +// }) + +.then((data) => { + console.log(require('util').inspect(data, {depth: null, colors: true})) +}) +.catch(console.error) diff --git a/p/nvv/index.js b/p/nvv/index.js new file mode 100644 index 00000000..8ebfaca8 --- /dev/null +++ b/p/nvv/index.js @@ -0,0 +1,38 @@ +'use strict' + +const products = require('./products') + +const transformReqBody = (body) => { + body.client = { + type: 'IPH', + id: 'NVV', + v: '5000300', + os: 'iOS 12.1.4', + name: 'NVVMobilPROD_APPSTORE' + } + body.ver = '1.18' + body.ext = 'NVV.6.0' + body.auth = {type: 'AID', aid: 'Kt8eNOH7qjVeSxNA'} + body.lang = 'de' + + return body +} + +const saarfahrplanProfile = { + locale: 'de-DE', + timezone: 'Europe/Berlin', + endpoint: 'https://auskunft.nvv.de/auskunft/bin/app/mgate.exe', + transformReqBody, + + // Although the app uses `mic` & `mac`, they don't seem to be necessary. + // addMicMac: true + + products: products, + + departuresGetPasslist: true, + trip: true, + radar: true, + reachableFrom: true +} + +module.exports = saarfahrplanProfile diff --git a/p/nvv/products.js b/p/nvv/products.js new file mode 100644 index 00000000..a4907b55 --- /dev/null +++ b/p/nvv/products.js @@ -0,0 +1,61 @@ +'use strict' + +module.exports = [ + // todo: what is `256`? + { + id: 'express', + mode: 'train', + bitmasks: [1], + name: 'InterCityExpress', + short: 'ICE', + default: true + }, + { + id: 'national', + mode: 'train', + bitmasks: [2], + name: 'EuroCity/InterCity', + short: 'EC/IC', + default: true + }, + { + id: 'regional', + mode: 'train', + bitmasks: [4], + name: 'Regionalzug', + short: 'RE/RB', + default: true + }, + { + id: 'regiotram', + mode: 'train', + bitmasks: [1024, 16, 8], // it is `1048` actually + name: 'RegioTram', + short: 'RegioTram', + default: true + }, + { + id: 'tram', + mode: 'train', + bitmasks: [4, 32], + name: 'Tram', + short: 'Tram', + default: true + }, + { + id: 'bus', + mode: 'bus', + bitmasks: [128, 64], // it is `192` actually + name: 'Bus', + short: 'Bus', + default: true + }, + { + id: 'on-call', + mode: 'taxi', // todo: or `bus`? + bitmasks: [512], + name: 'AnrufSammelTaxi', + short: 'Sammeltaxi', + default: true + } +] diff --git a/p/nvv/readme.md b/p/nvv/readme.md new file mode 100644 index 00000000..60b9fae0 --- /dev/null +++ b/p/nvv/readme.md @@ -0,0 +1,18 @@ +# NVV profile for `hafas-client` + +[*Nordhessischer Verkehrsverbund (NVV)*](https://en.wikipedia.org/wiki/Nordhessischer_Verkehrsverbund) is a local transport association in [Hesse](https://en.wikipedia.org/wiki/Hesse). This profile adds *NVV*-specific customizations to `hafas-client`. + +## Usage + +```js +const createClient = require('hafas-client') +const nvvProfile = require('hafas-client/p/nvv') + +// create a client with NVV profile +const client = createClient(nvvProfile, 'my-awesome-program') +``` + + +## Customisations + +- parses *NVV*-specific products (such as *RegioTram*) diff --git a/readme.md b/readme.md index 3c58d105..19f1275f 100644 --- a/readme.md +++ b/readme.md @@ -15,6 +15,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code *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) [Société Nationale des Chemins de Fer Luxembourgeois (CFL)](https://en.wikipedia.org/wiki/Société_Nationale_des_Chemins_de_Fer_Luxembourgeois) | - | [docs](p/cfl/readme.md) | [example code](p/cfl/example.js) | [src](p/cfl/index.js) [Hamburg public transport (HVV)](https://en.wikipedia.org/wiki/Hamburger_Verkehrsverbund) | - | [docs](p/hvv/readme.md) | [example code](p/hvv/example.js) | [src](p/hvv/index.js) +[*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) There are also client libraries that use the library, but contain their own customisations: