From 84637b2e960da0e77e483a1d4b7ea95cf7b14a2f Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 3 Mar 2020 00:35:16 +0100 Subject: [PATCH] add RSAG profile --- p/rsag/example.js | 43 ++++++++++++++++++++++++ p/rsag/index.js | 33 ++++++++++++++++++ p/rsag/products.js | 84 ++++++++++++++++++++++++++++++++++++++++++++++ p/rsag/readme.md | 18 ++++++++++ readme.md | 1 + 5 files changed, 179 insertions(+) create mode 100644 p/rsag/example.js create mode 100644 p/rsag/index.js create mode 100644 p/rsag/products.js create mode 100644 p/rsag/readme.md diff --git a/p/rsag/example.js b/p/rsag/example.js new file mode 100644 index 00000000..b46dc555 --- /dev/null +++ b/p/rsag/example.js @@ -0,0 +1,43 @@ +'use strict' + +const createClient = require('../..') +const rsagProfile = require('.') + +const client = createClient(rsagProfile, 'hafas-client-example') + +const rostockHbf = '8010304' +const güstrow = '8010153' +const albertEinsteinStr = { + type: 'location', + id: '990004201', + address: 'Rostock - Südstadt, Albert-Einstein-Straße 23', + latitude: 54.077208, longitude: 12.108299 +} + +client.journeys(rostockHbf, güstrow, {results: 1}) +// client.departures(rostockHbf, {duration: 1}) +// client.arrivals(rostockHbf, {duration: 10, linesOfStops: true}) +// client.locations('güstrow', {results: 2}) +// client.stop(rostockHbf, {linesOfStops: true}) // Dammtor +// client.nearby(albertEinsteinStr) +// client.radar({ +// north: 54.177, +// west: 11.959, +// south: 54.074, +// east: 12.258 +// }, {results: 10}) +// client.reachableFrom(albertEinsteinStr, { +// 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((data) => { + console.log(require('util').inspect(data, {depth: null, colors: true})) +}) +.catch(console.error) diff --git a/p/rsag/index.js b/p/rsag/index.js new file mode 100644 index 00000000..2a9d7459 --- /dev/null +++ b/p/rsag/index.js @@ -0,0 +1,33 @@ +'use strict' + +const products = require('./products') + +const transformReqBody = (ctx, body) => { + body.client = {type: 'WEB', id: 'RSAG', name: 'webapp'} + body.ext = 'VBN.2' + body.ver = '1.24' + body.auth = {type: 'AID', aid: 'tF5JTs25rzUhGrrl'} + + return body +} + +const hvvProfile = { + locale: 'de-DE', + timezone: 'Europe/Berlin', + endpoint: 'https://fahrplan.rsag-online.de/bin/mgate.exe', + + transformReqBody, + + products, + + trip: true, + radar: true, + reachableFrom: true, + + // todo: these fail ver >=1.21, see #164 + refreshJourney: false, + departuresGetPasslist: false, + departuresStbFltrEquiv: false, +} + +module.exports = hvvProfile diff --git a/p/rsag/products.js b/p/rsag/products.js new file mode 100644 index 00000000..8315fbb6 --- /dev/null +++ b/p/rsag/products.js @@ -0,0 +1,84 @@ +'use strict' + +module.exports = [ + { + id: 'ice', + mode: 'train', + bitmasks: [1], + name: 'InterCityExpress', + short: 'ICE', + default: true + }, + { + id: 'ic-ec', + mode: 'train', + bitmasks: [2], + name: 'InterCity & EuroCity', + short: 'IC/EC', + default: true + }, + { + id: 'long-distance-train', + mode: 'train', + bitmasks: [4], + name: 'InterRegio/high-speed train', + short: 'IR/other', + default: true + }, + { + id: 'regional-train', // todo: rename + mode: 'train', + bitmasks: [8], + name: 'regional train', + short: 'RE/RB', + default: true + }, + { + id: 's-bahn', + mode: 'train', + bitmasks: [16], + name: 'S-Bahn', + short: 'S', + default: true + }, + { + id: 'bus', + mode: 'bus', + bitmasks: [32], + name: 'Bus', + short: 'B', + default: true + }, + { + id: 'ferry', + mode: 'watercraft', + bitmasks: [64], + name: 'Schiff', + short: 'F', + default: true + }, + { + id: 'u-bahn', + mode: 'train', + bitmasks: [128], + name: 'U-Bahn', + short: 'U', + default: true + }, + { + id: 'tram', + mode: 'train', + bitmasks: [256], + name: 'Tram', + short: 'T', + default: true + }, + { + id: 'on-call', + mode: 'taxi', // todo: or `bus`? + bitmasks: [512], + name: 'Taxi/on-call vehicle', + short: 'AST', + default: true + } +] diff --git a/p/rsag/readme.md b/p/rsag/readme.md new file mode 100644 index 00000000..a901ba82 --- /dev/null +++ b/p/rsag/readme.md @@ -0,0 +1,18 @@ +# RSAG profile for `hafas-client` + +[*Rostocker Straßenbahn AG (RSAG)*](https://de.wikipedia.org/wiki/Rostocker_Straßenbahn_AG) is the local transport provider in [Rostock](https://en.wikipedia.org/wiki/Rostock). This profile adds *RSAG*-specific customizations to `hafas-client`. + +## Usage + +```js +const createClient = require('hafas-client') +const rsagProfile = require('hafas-client/p/rsag') + +// create a client with RSAG profile +const client = createClient(rsagProfile, 'my-awesome-program') +``` + + +## Customisations + +- parses *RSAG*-specific products diff --git a/readme.md b/readme.md index 0e82c7c5..7eda85bf 100644 --- a/readme.md +++ b/readme.md @@ -223,6 +223,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) +[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) There are also libraries that use `hafas-client` and pass their own profile in: