From 33dab455cec8c6099722bb0fa0eb730c7da0dde5 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 26 Jul 2021 17:30:11 +0200 Subject: [PATCH] =?UTF-8?q?add=20TPG=20profile=20=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #208 --- p/readme.md | 1 + p/tpg/base.json | 13 +++ p/tpg/example.js | 53 +++++++++++ p/tpg/index.js | 87 +++++++++++++++++++ p/tpg/readme.md | 15 ++++ .../03cfb56ddfe0ed19d58f71b68c312c6a.headers | 13 +-- tools/pull-profile-base-data.sh | 1 + 7 files changed, 173 insertions(+), 10 deletions(-) create mode 100644 p/tpg/base.json create mode 100644 p/tpg/example.js create mode 100644 p/tpg/index.js create mode 100644 p/tpg/readme.md diff --git a/p/readme.md b/p/readme.md index 9a8597f2..3081e5d3 100644 --- a/p/readme.md +++ b/p/readme.md @@ -41,6 +41,7 @@ HAFAS endpoint | wrapper library | docs | example code | profile name [Salzburg public transport (SVV)](https://de.wikipedia.org/wiki/Salzburger_Verkehrsverbund) | - | [docs](svv/readme.md) | [example](svv/example.js) | [`svv`](svv) [Verkehrsverbund Tirol (VVT)](https://de.wikipedia.org/wiki/Verkehrsverbund_Tirol) | - | [docs](vvt/readme.md) | [example](vvt/example.js) | [`vvt`](vvt) [*Kärntner Linien/Verkehrsverbund Kärnten (VKG/VVK)*](https://de.wikipedia.org/wiki/Verkehrsverbund_Kärnten) | - | [docs](vkg/readme.md) | [example](vkg/example.js) | [`vkg`](vkg) +[*Transports publics genevois (TPG)*](https://en.wikipedia.org/wiki/Geneva_Public_Transport) (Geneva) | - | [docs](tpg/readme.md) | [example](tpg/example.js) | [`tpg`](tpg) [*BLS AG*](https://en.wikipedia.org/wiki/BLS_AG) (Bern) | - | [docs](bls/readme.md) | [example](bls/example.js) | [`bls`](bls) [Zürich public transport (ZVV)](https://en.wikipedia.org/wiki/Zürcher_Verkehrsverbund) | - | [docs](zvv/readme.md) | [example](zvv/example.js) | [`zvv`](zvv) diff --git a/p/tpg/base.json b/p/tpg/base.json new file mode 100644 index 00000000..ec39ce14 --- /dev/null +++ b/p/tpg/base.json @@ -0,0 +1,13 @@ +{ + "auth": { + "type": "AID", + "aid": "9CZsdl5PqX8n5D6b" + }, + "client": { + "type": "WEB", + "id": "HAFAS", + "name": "webapp" + }, + "endpoint": "https://tpg-webapp.hafas.de/bin/mgate.exe", + "defaultLanguage": "fr" +} diff --git a/p/tpg/example.js b/p/tpg/example.js new file mode 100644 index 00000000..c3e1df17 --- /dev/null +++ b/p/tpg/example.js @@ -0,0 +1,53 @@ +'use strict' + +const createClient = require('../..') +const tpgProfile = require('.') + +const client = createClient(tpgProfile, 'hafas-client-example') + +const miremont = '100449' +const moillebeau = '100451' + +client.journeys(miremont, moillebeau, {results: 1, stopovers: true}) + +// .then(({journeys}) => { +// const [journey] = journeys +// return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) +// }) + +// .then(({journeys}) => { +// const [journey] = journeys +// const leg = journey.legs[0] +// return client.trip(leg.tripId, leg.line.name, {polyline: true}) +// }) + +// client.departures(miremont, {duration: 1}) +// client.arrivals(miremont, {duration: 10, linesOfStops: true}) +// client.radar({ +// north: 46.1849, +// east: 6.1919, +// south: 46.2215, +// west: 6.1192, +// }, {results: 10}) + +// client.locations('miremont', {results: 3}) +// client.stop(miremont, {linesOfStops: true}) +// client.nearby({ +// type: 'location', +// latitude: 46.197768, +// longitude: 6.148046, +// }, {distance: 500}) +// client.reachableFrom({ +// type: 'location', +// id: '990001624', +// address: 'Cours des Bastions 10, 1205 Genève', +// latitude: 46.197768, +// longitude: 6.148046, +// }, { +// maxDuration: 10, +// }) + +.then((data) => { + console.log(require('util').inspect(data, {depth: null, colors: true})) +}) +.catch(console.error) diff --git a/p/tpg/index.js b/p/tpg/index.js new file mode 100644 index 00000000..58333209 --- /dev/null +++ b/p/tpg/index.js @@ -0,0 +1,87 @@ +'use strict' + +const baseProfile = require('./base.json') + +const products = [{ + id: 'tgv', + mode: 'train', + bitmasks: [1], + name: 'TGV', + short: 'TGV', + default: true, +}, { + id: 'intercites', + mode: 'train', + bitmasks: [2], + name: 'Intercités', + short: 'Intercités', + default: true, +}, { + id: 'ir', + mode: 'train', + bitmasks: [4], + name: 'IR', + short: 'IR', + default: true, +}, { + id: 'train-direct', + mode: 'train', + bitmasks: [8], + name: 'Train direct', + short: 'Train direct', + default: true, +}, { + id: 'bateau', + mode: 'watercraft', + bitmasks: [16], + name: 'Bateau', + short: 'Bateau', + default: true, +}, { + id: 'regio-express', + mode: 'train', + bitmasks: [32], + name: 'Regio Express', + short: 'Regio Express', + default: true, +}, { + id: 'bus', + mode: 'bus', + bitmasks: [64], + name: 'Bus', + short: 'Bus', + default: true, +}, { + id: 'transport-a-cables', + mode: 'gondola', + bitmasks: [128], + name: 'Transport à câbles', + short: 'Transport à câbles', + default: true, +}, { + id: 'tram', + mode: 'train', + bitmasks: [512], + name: 'Tram', + short: 'Tram', + default: true, +}] + +const tpgProfile = { + ...baseProfile, + locale: 'de-DE', + timezone: 'Europe/Berlin', + ver: '1.40', + + products, + + trip: true, + radar: true, + refreshJourneyUseOutReconL: true, + reachableFrom: true, + + departuresGetPasslist: false, + departuresStbFltrEquiv: false, +} + +module.exports = tpgProfile diff --git a/p/tpg/readme.md b/p/tpg/readme.md new file mode 100644 index 00000000..4ed968d5 --- /dev/null +++ b/p/tpg/readme.md @@ -0,0 +1,15 @@ +# TPG profile for `hafas-client` + +[*Transports publics genevois (TPG)*](https://en.wikipedia.org/wiki/Geneva_Public_Transport) is the local transport provider of the [Canton of Geneva](https://en.wikipedia.org/wiki/Canton_of_Geneva). This profile adds *TPG* support to `hafas-client`. + +## Usage + +```js +const createClient = require('hafas-client') +const tpgProfile = require('hafas-client/p/TPG') + +// create a client with TPG profile +const client = createClient(tpgProfile, 'my-awesome-program') +``` + +Check out the [code examples](example.js). diff --git a/test/e2e/fixtures/03cfb56ddfe0ed19d58f71b68c312c6a.headers b/test/e2e/fixtures/03cfb56ddfe0ed19d58f71b68c312c6a.headers index 7f63bc6f..10059f3b 100644 --- a/test/e2e/fixtures/03cfb56ddfe0ed19d58f71b68c312c6a.headers +++ b/test/e2e/fixtures/03cfb56ddfe0ed19d58f71b68c312c6a.headers @@ -1,14 +1,7 @@ { - "statusCode": 200, - "headers": { - "date": "Mon, 26 Jul 2021 15:45:01 GMT", - "server": "Apache", - "content-length": "3720", - "connection": "close", - "content-type": "application/json; charset=utf-8" - }, + "timeout": true, + "time": 0, "url": "https://bls.hafas.de/bin/mgate.exe", - "time": 1023, "request": { "method": "POST", "headers": { @@ -22,7 +15,7 @@ "application/json" ], "user-agent": [ - "pu1a6b1bee0fa6blic-transport/hafas-client:test" + "public-transport/hafas-client:tes84543f948adat" ], "Content-Length": [ "706" diff --git a/tools/pull-profile-base-data.sh b/tools/pull-profile-base-data.sh index 29a836cb..b210517d 100755 --- a/tools/pull-profile-base-data.sh +++ b/tools/pull-profile-base-data.sh @@ -62,4 +62,5 @@ node -p "$query" "$src/de/vrn-hafas-mgate.json" >../p/vrn/base.json node -p "$query" "$src/de/vsn-hafas-mgate.json" >../p/vsn/base.json node -p "$query" "$src/at/vvt-hafas-mgate.json" >../p/vvt/base.json node -p "$query" "$src/ch/bls-hafas-mgate.json" >../p/bls/base.json +node -p "$query" "$src/ch/tpg-hafas-mgate.json" >../p/tpg/base.json node -p "$query" "$src/ch/zvv-hafas-mgate.json" >../p/zvv/base.json