From 3e01303e43148505452cac64b81fccc437344b54 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 12 Apr 2018 21:25:40 +0200 Subject: [PATCH] CFL profile :sparkles: --- p/cfl/example.js | 33 +++++++++++++++++++++++++++++++++ p/cfl/index.js | 32 ++++++++++++++++++++++++++++++++ p/cfl/products.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ p/cfl/readme.md | 18 ++++++++++++++++++ parse/operator.js | 4 +++- readme.md | 1 + 6 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 p/cfl/example.js create mode 100644 p/cfl/index.js create mode 100644 p/cfl/products.js create mode 100644 p/cfl/readme.md diff --git a/p/cfl/example.js b/p/cfl/example.js new file mode 100644 index 00000000..f8799895 --- /dev/null +++ b/p/cfl/example.js @@ -0,0 +1,33 @@ +'use strict' + +const createClient = require('../..') +const cflProfile = require('.') + +const client = createClient(cflProfile) + +// from Mersch to Pfaffenthal-Kirchberg +// client.journeys('009864348', '008200102', {results: 1}) +client.departures('009864348', { duration: 5 }) +// client.locations('Pfaffenthal Kirchberg', {results: 2}) +// client.station('009864348') // Mersch +// client.nearby({ +// type: 'location', +// latitude: 49.7523, +// longitude: 6.1103 +// }, {distance: 500}) +// client.radar({ +// north: 49.9, +// west: 6.11, +// south: 49.7, +// east: 6.13 +// }, {results: 10}) + +// .then(([journey]) => { +// const leg = journey.legs[0] +// return client.journeyLeg(leg.id, leg.line.name) +// }) + +.then(data => { + console.log(require('util').inspect(data, { depth: null })) +}) +.catch(console.error) diff --git a/p/cfl/index.js b/p/cfl/index.js new file mode 100644 index 00000000..e6dc6a79 --- /dev/null +++ b/p/cfl/index.js @@ -0,0 +1,32 @@ +'use strict' + +const products = require('./products') + +const transformReqBody = (body) => { + body.client = { + type: 'IPH', + id: 'HAFAS', + v: '4000000', + name: 'cflPROD-STORE', + os: 'iPhone OS 9.3.5' + } + body.ver = '1.16' + body.auth = {aid: 'ALT2vl7LAFDFu2dz'} + body.lang = 'de' + + return body +} + +const cflProfile = { + locale: 'de-LU', + timezone: 'Europe/Luxembourg', + endpoint: 'https://horaires.cfl.lu/bin/mgate.exe', + transformReqBody, + + products: products, + + journeyLeg: true, + radar: true +} + +module.exports = cflProfile; diff --git a/p/cfl/products.js b/p/cfl/products.js new file mode 100644 index 00000000..027d1bcc --- /dev/null +++ b/p/cfl/products.js @@ -0,0 +1,45 @@ +'use strict' + +module.exports = [ + // todo: other bits + { + id: 'express-train', + mode: 'train', + bitmasks: [1, 2], + name: 'TGV, ICE, EuroCity', + short: 'TGV/ICE/EC', + default: true + }, + { + id: 'local-train', + mode: 'train', + bitmasks: [8, 16], + name: 'local trains', + short: 'local', + default: true + }, + { + id: 'tram', + mode: 'train', + bitmasks: [256], + name: 'tram', + short: 'tram', + default: true + }, + { + id: 'bus', + mode: 'bus', + bitmasks: [32], + name: 'bus', + short: 'bus', + default: true + }, + { + id: 'gondola', + mode: 'gondola', + bitmasks: [512], + name: 'Fun', // taken from the horaires.cfl.lu website + short: 'Fun', + default: true + } +] diff --git a/p/cfl/readme.md b/p/cfl/readme.md new file mode 100644 index 00000000..36b6632b --- /dev/null +++ b/p/cfl/readme.md @@ -0,0 +1,18 @@ +# CFL profile for `hafas-client` + +The [*Société Nationale des Chemins de Fer Luxembourgeois (CFL)*](https://en.wikipedia.org/wiki/Société_Nationale_des_Chemins_de_Fer_Luxembourgeois) is the national railway company of [Luxembourg](https://en.wikipedia.org/wiki/Luxembourg). This profile adds *CFL*-specific customisations to `hafas-client`. + +## Usage + +```js +const createClient = require('hafas-client') +const cflProfile = require('hafas-client/p/cfl') + +// create a client with CFL profile +const client = createClient(cflProfile) +``` + + +## Customisations + +- *CFL*-specific products (such as [*Standseilbahn_Pfaffenthal-Kirchberg*](https://de.wikipedia.org/wiki/Standseilbahn_Pfaffenthal-Kirchberg)) diff --git a/parse/operator.js b/parse/operator.js index 372b525e..cac2db21 100644 --- a/parse/operator.js +++ b/parse/operator.js @@ -3,10 +3,12 @@ const slugg = require('slugg') const parseOperator = (profile, a) => { + const name = a.name && a.name.trim() + if (!name) return null return { type: 'operator', id: slugg(a.name), // todo: find a more reliable way - name: a.name + name } } diff --git a/readme.md b/readme.md index 013fc75a..a15d3df6 100644 --- a/readme.md +++ b/readme.md @@ -13,6 +13,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code [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 München*](https://en.wikipedia.org/wiki/Munich_S-Bahn) | - | [docs](p/sbahn-muenchen/readme.md) | [example code](p/sbahn-muenchen/example.js) | [src](p/sbahn-muenchen/index.js) *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) There are also client libraries that use the library, but contain their own customisations: