mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
add SNCB/NMBS profile
This commit is contained in:
parent
ce76c1f983
commit
01b3693271
6 changed files with 210 additions and 0 deletions
49
p/sncb/digicert-sha2-secure-server-ca.crt.pem
Normal file
49
p/sncb/digicert-sha2-secure-server-ca.crt.pem
Normal file
|
@ -0,0 +1,49 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIElDCCA3ygAwIBAgIQAf2j627KdciIQ4tyS8+8kTANBgkqhkiG9w0BAQsFADBh
|
||||
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
|
||||
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
|
||||
QTAeFw0xMzAzMDgxMjAwMDBaFw0yMzAzMDgxMjAwMDBaME0xCzAJBgNVBAYTAlVT
|
||||
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxJzAlBgNVBAMTHkRpZ2lDZXJ0IFNIQTIg
|
||||
U2VjdXJlIFNlcnZlciBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
|
||||
ANyuWJBNwcQwFZA1W248ghX1LFy949v/cUP6ZCWA1O4Yok3wZtAKc24RmDYXZK83
|
||||
nf36QYSvx6+M/hpzTc8zl5CilodTgyu5pnVILR1WN3vaMTIa16yrBvSqXUu3R0bd
|
||||
KpPDkC55gIDvEwRqFDu1m5K+wgdlTvza/P96rtxcflUxDOg5B6TXvi/TC2rSsd9f
|
||||
/ld0Uzs1gN2ujkSYs58O09rg1/RrKatEp0tYhG2SS4HD2nOLEpdIkARFdRrdNzGX
|
||||
kujNVA075ME/OV4uuPNcfhCOhkEAjUVmR7ChZc6gqikJTvOX6+guqw9ypzAO+sf0
|
||||
/RR3w6RbKFfCs/mC/bdFWJsCAwEAAaOCAVowggFWMBIGA1UdEwEB/wQIMAYBAf8C
|
||||
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IJF
|
||||
PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
|
||||
YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
|
||||
CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
|
||||
-----END CERTIFICATE-----
|
41
p/sncb/example.js
Normal file
41
p/sncb/example.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
'use strict'
|
||||
|
||||
const createClient = require('../..')
|
||||
const sncbProfile = require('.')
|
||||
|
||||
const client = createClient(sncbProfile, 'hafas-client-example')
|
||||
|
||||
const gentStPieters = '8892007'
|
||||
const bruxellesMidi = '8814001'
|
||||
const gentPaddenhoek = {
|
||||
type: 'location',
|
||||
address: 'Gent, Paddenhoek',
|
||||
latitude: 51.0517, longitude: 3.724878,
|
||||
}
|
||||
|
||||
// client.journeys(gentStPieters, bruxellesMidi, {stopovers: true, remarks: true})
|
||||
// .then(({journeys}) => {
|
||||
// const leg = journeys[0].legs[0]
|
||||
// return client.trip(leg.tripId, leg.line.name, {polyline: true})
|
||||
// })
|
||||
// .then(({journeys}) => {
|
||||
// return client.refreshJourney(journeys[0].refreshToken, {remarks: true})
|
||||
// })
|
||||
|
||||
// client.departures(gentStPieters)
|
||||
// client.arrivals(gentStPieters, {duration: 10, linesOfStops: true})
|
||||
// client.locations('gent')
|
||||
// client.stop(gentStPieters, {linesOfStops: true})
|
||||
// client.nearby(gentPaddenhoek)
|
||||
// client.radar({
|
||||
// north: 51.065,
|
||||
// west: 3.688,
|
||||
// south: 51.04,
|
||||
// east: 3.748
|
||||
// }, {results: 10})
|
||||
// client.reachableFrom(gentPaddenhoek)
|
||||
|
||||
.then((data) => {
|
||||
console.log(require('util').inspect(data, {depth: null, colors: true}))
|
||||
})
|
||||
.catch(console.error)
|
40
p/sncb/index.js
Normal file
40
p/sncb/index.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
'use strict'
|
||||
|
||||
const {readFileSync} = require('fs')
|
||||
const {join} = require('path')
|
||||
const {Agent} = require('https')
|
||||
const products = require('./products')
|
||||
|
||||
// `www.belgianrail.be:443` doesn't provide the necessary CA certificate
|
||||
// chain for Node.js to trust the certificate, so we manually add it.
|
||||
// todo: fix this properly, e.g. by letting them know
|
||||
const ca = readFileSync(join(__dirname, 'digicert-sha2-secure-server-ca.crt.pem'))
|
||||
const agent = new Agent({ca})
|
||||
const transformReq = (ctx, req) => ({...req, agent})
|
||||
|
||||
const transformReqBody = ({opt}, body) => {
|
||||
body.client = {type: 'IPH', id: 'SNCB', name: 'sncb', v: '4030200'}
|
||||
body.ver = '1.16'
|
||||
body.auth = {type: 'AID', aid: 'sncb-mobi'}
|
||||
body.lang = opt.language || 'fr'
|
||||
|
||||
return body
|
||||
}
|
||||
|
||||
const sncbProfile = {
|
||||
locale: 'fr-BE',
|
||||
timezone: 'Europe/Brussels',
|
||||
endpoint: 'https://www.belgianrail.be/jp/sncb-nmbs-routeplanner/mgate.exe',
|
||||
|
||||
transformReq,
|
||||
transformReqBody,
|
||||
|
||||
products,
|
||||
|
||||
trip: true,
|
||||
refreshJourney: true,
|
||||
radar: true,
|
||||
// todo: `reachableFrom: true` fails with `H9240`
|
||||
}
|
||||
|
||||
module.exports = sncbProfile
|
61
p/sncb/products.js
Normal file
61
p/sncb/products.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
'use strict'
|
||||
|
||||
// https://www.belgiantrain.be/en/support/faq/faq-routes-schedules/faq-train-types
|
||||
module.exports = [ // todo: 2, 8, 32, 128
|
||||
{
|
||||
id: 'high-speed-train',
|
||||
mode: 'train',
|
||||
bitmasks: [1],
|
||||
name: 'high-speed train',
|
||||
short: 'HST',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'intercity-p',
|
||||
mode: 'train',
|
||||
bitmasks: [4],
|
||||
name: 'InterCity/Peak',
|
||||
short: 'IC/P',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 's-train',
|
||||
mode: 'train',
|
||||
bitmasks: [16],
|
||||
name: 'S-train',
|
||||
short: 'S',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'local-train',
|
||||
mode: 'train',
|
||||
bitmasks: [64],
|
||||
name: 'local train',
|
||||
short: 'L',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'metro',
|
||||
mode: 'train',
|
||||
bitmasks: [256],
|
||||
name: 'Metro',
|
||||
short: 'M',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'bus',
|
||||
mode: 'bus',
|
||||
bitmasks: [512],
|
||||
name: 'bus',
|
||||
short: 'bus',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'tram',
|
||||
mode: 'train',
|
||||
bitmasks: [1024],
|
||||
name: 'tram',
|
||||
short: 'tram',
|
||||
default: true
|
||||
}
|
||||
]
|
18
p/sncb/readme.md
Normal file
18
p/sncb/readme.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# SNCB profile for `hafas-client`
|
||||
|
||||
[*Société nationale des chemins de fer belges (SNCB)*/*Nationale Maatschappij der Belgische Spoorwegen (NMBS)*](https://en.wikipedia.org/wiki/National_Railway_Company_of_Belgium) is the major public transport provider of [Belgium](https://en.wikipedia.org/wiki/Belgium). This profile adds *SNCB*-specific customizations to `hafas-client`.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const createClient = require('hafas-client')
|
||||
const sncbProfile = require('hafas-client/p/sncb')
|
||||
|
||||
// create a client with SNCB profile
|
||||
const client = createClient(sncbProfile, 'my-awesome-program')
|
||||
```
|
||||
|
||||
|
||||
## Customisations
|
||||
|
||||
- parses *SNCB*-specific products
|
|
@ -207,6 +207,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code
|
|||
---------------|------------------|------|---------|------------
|
||||
[Deutsche Bahn (DB)](https://en.wikipedia.org/wiki/Deutsche_Bahn) | [`db-hafas`](https://github.com/derhuerst/db-hafas) | [docs](p/db/readme.md) | [example code](p/db/example.js) | [src](p/db/index.js)
|
||||
[Polskie Koleje Państwowe (PKP)](https://en.wikipedia.org/wiki/Polish_State_Railways) | [`pkp-hafas`](https://github.com/juliuste/pkp-hafas) | [docs](p/pkp/readme.md) | [example code](p/pkp/example.js) | [src](p/pkp/index.js)
|
||||
[Belgian National Railways (SNCB/NMBS)](https://en.wikipedia.org/wiki/National_Railway_Company_of_Belgium) | - | [docs](p/sncb/readme.md) | [example code](p/sncb/example.js) | [src](p/sncb/index.js)
|
||||
[Berlin & Brandenburg public transport (VBB)](https://en.wikipedia.org/wiki/Verkehrsverbund_Berlin-Brandenburg) | [`vbb-hafas`](https://github.com/derhuerst/vbb-hafas) | [docs](p/vbb/readme.md) | [example code](p/vbb/example.js) | [src](p/vbb/index.js)
|
||||
[Berlin public transport (BVG)](https://en.wikipedia.org/wiki/Berliner_Verkehrsbetriebe) | [`bvg-hafas`](https://github.com/derhuerst/bvg-hafas) | [docs](p/bvg/readme.md) | [example code](p/bvg/example.js) | [src](p/bvg/index.js)
|
||||
[Österreichische Bundesbahnen (ÖBB)](https://en.wikipedia.org/wiki/Austrian_Federal_Railways) | [`oebb-hafas`](https://github.com/juliuste/oebb-hafas) | [docs](p/oebb/readme.md) | [example code](p/oebb/example.js) | [src](p/oebb/index.js)
|
||||
|
|
Loading…
Add table
Reference in a new issue