diff --git a/p/sbahn-munich/example.js b/p/sbahn-munich/example.js new file mode 100644 index 00000000..87a5f75c --- /dev/null +++ b/p/sbahn-munich/example.js @@ -0,0 +1,49 @@ +'use strict' + +const createClient = require('../..') +const vbbProfile = require('.') + +const client = createClient(vbbProfile, 'hafas-client-example') + +// Mittersendling to Charlottenburg +// client.journeys('8004154', '0621790', {results: 1, polylines: true}) +client.departures('8004154', {duration: 5}) +// client.arrivals('8004154', {duration: 10, stationLines: true}) +// client.locations('mittersendling', {results: 5}) +// client.station('8004154', {stationLines: true}) // Mittersendling +// client.nearby({ +// type: 'location', +// latitude: 48.153858, +// longitude: 11.533059 +// }, {distance: 750}) +// client.radar({ +// north: 48.145121, +// west: 11.543736, +// south: 48.138339, +// east: 11.553776 +// }, {results: 10}) +// client.reachableFrom({ +// type: 'location', +// address: 'Pötschnerstraße 3, neuhausen', +// latitude: 48.152499, +// longitude: 11.531695 +// }, { +// when: new Date('2018-08-27T10:00:00+0200'), +// maxDuration: 20 +// }) + +// .then(([journey]) => { +// const leg = journey.legs.find(leg => leg.line) +// return client.trip(leg.id, leg.line.name, {polyline: true}) +// }) + +// .then(([journey]) => { +// return client.refreshJourney(journey.refreshToken, { +// stopovers: true, remarks: true +// }) +// }) + +.then((data) => { + console.log(require('util').inspect(data, {depth: null})) +}) +.catch(console.error) diff --git a/p/sbahn-munich/index.js b/p/sbahn-munich/index.js new file mode 100644 index 00000000..ec2690eb --- /dev/null +++ b/p/sbahn-munich/index.js @@ -0,0 +1,31 @@ +'use strict' + +const products = require('./products') + +const transformReqBody = (body) => { + body.client = {type: 'IPA', id: 'DB-REGIO-MVV', name: 'RegioNavigator', v: '1000030'} + body.ext = 'DB.R15.12.a' + body.ver = '1.15' + body.auth = {type: 'AID', aid: 'd491MVVhz9ZZts23'} + + return body +} + +const sBahnMunichProfile = { + locale: 'de-DE', + timezone: 'Europe/Berlin', + endpoint: 'https://s-bahn-muenchen.hafas.de/bin/540/mgate.exe', + + salt: Buffer.from('ggnvMVV8RTt67gh1', 'utf8'), + addMicMac: true, + transformReqBody, + + products, + + trip: true, + radar: true, + refreshJourney: true, + reachableFrom: true +} + +module.exports = sBahnMunichProfile diff --git a/p/sbahn-munich/products.js b/p/sbahn-munich/products.js new file mode 100644 index 00000000..638f4642 --- /dev/null +++ b/p/sbahn-munich/products.js @@ -0,0 +1,77 @@ +'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: 'ir-d', + mode: 'train', + bitmasks: [4], + name: 'Interregio/Schnellzug', + short: 'IRE', + default: true + }, + { + id: 'region', + mode: 'train', + bitmasks: [8], + name: 'Regio- und Nahverkehr', + short: 'RE/RB', + default: true + }, + { + id: 'sbahn', + mode: 'train', + bitmasks: [16], + name: 'S-Bahn', + short: 'S', + default: true + }, + { + id: 'bus', + mode: 'bus', + bitmasks: [32], + name: 'Bus', + short: 'Bus', + default: true + }, + // todo: 64 + { + id: 'ubahn', + mode: 'train', + bitmasks: [128], + name: 'U-Bahn', + short: 'U', + default: true + }, + { + id: 'tram', + mode: 'train', + bitmasks: [256], + name: 'Straßenbahn', + short: 'Tram', + default: true + }, + { + id: 'on-call', + mode: 'taxi', // todo: or `bus`? + bitmasks: [512], + name: 'Anrufsammeltaxi', + short: 'Sammeltaxi', + default: true + } +] diff --git a/p/sbahn-munich/readme.md b/p/sbahn-munich/readme.md new file mode 100644 index 00000000..9e06a03a --- /dev/null +++ b/p/sbahn-munich/readme.md @@ -0,0 +1,13 @@ +# S-Bahn München profile for `hafas-client` + +[*S-Bahn München*](https://en.wikipedia.org/wiki/Munich_S-Bahn) runs commuter trains in [Munich](https://en.wikipedia.org/wiki/Munich). This profile adapts `hafas-client` to their HAFAS endpoint. + +## Usage + +```js +const createClient = require('hafas-client') +const sMunichProfile = require('hafas-client/p/sbahn-munich') + +// create a client with S-Bahn München profile +const client = createClient(sMunichProfile, 'my-awesome-program') +``` diff --git a/readme.md b/readme.md index 459b4382..fbbef98a 100644 --- a/readme.md +++ b/readme.md @@ -11,6 +11,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code [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) [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* Munich](https://en.wikipedia.org/wiki/Munich_S-Bahn) | - | [docs](p/sbahn-munich/readme.md) | [example code](p/sbahn-munich/example.js) | [src](p/sbahn-munich/index.js) [![npm version](https://img.shields.io/npm/v/hafas-client.svg)](https://www.npmjs.com/package/hafas-client) [![build status](https://img.shields.io/travis/public-transport/hafas-client.svg?branch=master)](https://travis-ci.org/public-transport/hafas-client)