mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
parent
cec4f4dcaf
commit
24c2cc6ea4
10 changed files with 265 additions and 1 deletions
13
p/bls/base.json
Normal file
13
p/bls/base.json
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"auth": {
|
||||||
|
"type": "AID",
|
||||||
|
"aid": "3jkAncud78HSoqclmN54812A"
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"type": "WEB",
|
||||||
|
"id": "HAFAS",
|
||||||
|
"name": "webapp"
|
||||||
|
},
|
||||||
|
"endpoint": "https://bls.hafas.de/bin/mgate.exe",
|
||||||
|
"defaultLanguage": "de"
|
||||||
|
}
|
53
p/bls/example.js
Normal file
53
p/bls/example.js
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const createClient = require('../..')
|
||||||
|
const blsProfile = require('.')
|
||||||
|
|
||||||
|
const client = createClient(blsProfile, 'hafas-client-example')
|
||||||
|
|
||||||
|
const bernDennigkofengässli = '8590093'
|
||||||
|
const münsingenSpital = '8578932'
|
||||||
|
|
||||||
|
client.journeys(bernDennigkofengässli, münsingenSpital, {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(bernDennigkofengässli, {duration: 1})
|
||||||
|
// client.arrivals(bernDennigkofengässli, {duration: 10, linesOfStops: true})
|
||||||
|
// client.radar({
|
||||||
|
// north: 46.969,
|
||||||
|
// west: 7.3941,
|
||||||
|
// south: 46.921,
|
||||||
|
// east: 7.5141,
|
||||||
|
// }, {results: 10})
|
||||||
|
|
||||||
|
// client.locations('münsingen spital', {results: 3})
|
||||||
|
// client.stop(bernDennigkofengässli, {linesOfStops: true})
|
||||||
|
// client.nearby({
|
||||||
|
// type: 'location',
|
||||||
|
// latitude: 53.554422,
|
||||||
|
// longitude: 9.977934
|
||||||
|
// }, {distance: 500})
|
||||||
|
// client.reachableFrom({
|
||||||
|
// type: 'location',
|
||||||
|
// id: '990017698',
|
||||||
|
// address: 'Bern, Schänzlihalde 17',
|
||||||
|
// latitude: 46.952835,
|
||||||
|
// longitude: 7.447527,
|
||||||
|
// }, {
|
||||||
|
// maxDuration: 10,
|
||||||
|
// })
|
||||||
|
|
||||||
|
.then((data) => {
|
||||||
|
console.log(require('util').inspect(data, {depth: null, colors: true}))
|
||||||
|
})
|
||||||
|
.catch(console.error)
|
94
p/bls/index.js
Normal file
94
p/bls/index.js
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const baseProfile = require('./base.json')
|
||||||
|
|
||||||
|
const products = [{
|
||||||
|
id: 'ice',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [1],
|
||||||
|
name: 'ICE',
|
||||||
|
short: 'ICE',
|
||||||
|
default: true,
|
||||||
|
}, {
|
||||||
|
id: 'ic-ec',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [2],
|
||||||
|
name: 'IC/EC',
|
||||||
|
short: 'IC/EC',
|
||||||
|
default: true,
|
||||||
|
}, {
|
||||||
|
id: 'ir',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [4],
|
||||||
|
name: 'IR',
|
||||||
|
short: 'IR',
|
||||||
|
default: true,
|
||||||
|
}, {
|
||||||
|
id: 'local-train',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [8],
|
||||||
|
name: 'Nahverkehr',
|
||||||
|
short: 'Nahverkehr',
|
||||||
|
default: true,
|
||||||
|
}, {
|
||||||
|
id: 'watercraft',
|
||||||
|
mode: 'watercraft',
|
||||||
|
bitmasks: [16],
|
||||||
|
name: 'Schiff',
|
||||||
|
short: 'Schiff',
|
||||||
|
default: true,
|
||||||
|
}, {
|
||||||
|
id: 's-bahn',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [32],
|
||||||
|
name: 'S-Bahn',
|
||||||
|
short: 'S',
|
||||||
|
default: true,
|
||||||
|
}, {
|
||||||
|
id: 'bus',
|
||||||
|
mode: 'bus',
|
||||||
|
bitmasks: [64],
|
||||||
|
name: 'Bus',
|
||||||
|
short: 'Bus',
|
||||||
|
default: true,
|
||||||
|
}, {
|
||||||
|
id: 'funicular',
|
||||||
|
mode: 'gondola',
|
||||||
|
bitmasks: [128],
|
||||||
|
name: 'Seilbahn',
|
||||||
|
short: 'Seilbahn',
|
||||||
|
default: true,
|
||||||
|
}, {
|
||||||
|
id: 'tram',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [512],
|
||||||
|
name: 'Tram',
|
||||||
|
short: 'Tram',
|
||||||
|
default: true,
|
||||||
|
}, {
|
||||||
|
id: 'car-shuttle-train',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [4096],
|
||||||
|
name: 'Autoverlad',
|
||||||
|
short: 'Autoverlad',
|
||||||
|
default: true,
|
||||||
|
}]
|
||||||
|
|
||||||
|
const blsProfile = {
|
||||||
|
...baseProfile,
|
||||||
|
locale: 'de-DE',
|
||||||
|
timezone: 'Europe/Berlin',
|
||||||
|
ver: '1.46',
|
||||||
|
|
||||||
|
products,
|
||||||
|
|
||||||
|
trip: true,
|
||||||
|
radar: true,
|
||||||
|
refreshJourneyUseOutReconL: true,
|
||||||
|
reachableFrom: true,
|
||||||
|
|
||||||
|
departuresGetPasslist: false,
|
||||||
|
departuresStbFltrEquiv: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = blsProfile
|
15
p/bls/readme.md
Normal file
15
p/bls/readme.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# BLS profile for `hafas-client`
|
||||||
|
|
||||||
|
[*BLS AG*](https://en.wikipedia.org/wiki/BLS_AG) is the local transport provider of the [Canton of Bern](https://en.wikipedia.org/wiki/Canton_of_Bern). This profile adds *BLS* support to `hafas-client`.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
const createClient = require('hafas-client')
|
||||||
|
const blsProfile = require('hafas-client/p/BLS')
|
||||||
|
|
||||||
|
// create a client with BLS profile
|
||||||
|
const client = createClient(blsProfile, 'my-awesome-program')
|
||||||
|
```
|
||||||
|
|
||||||
|
Check out the [code examples](example.js).
|
|
@ -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)
|
[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)
|
[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)
|
[*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)
|
||||||
|
[*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)
|
[Zürich public transport (ZVV)](https://en.wikipedia.org/wiki/Zürcher_Verkehrsverbund) | - | [docs](zvv/readme.md) | [example](zvv/example.js) | [`zvv`](zvv)
|
||||||
|
|
||||||
## writing your own
|
## writing your own
|
||||||
|
|
51
test/e2e/bls.js
Normal file
51
test/e2e/bls.js
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const tap = require('tap')
|
||||||
|
|
||||||
|
const {createWhen} = require('./lib/util')
|
||||||
|
const createClient = require('../..')
|
||||||
|
const blsProfile = require('../../p/bls')
|
||||||
|
const createValidate = require('./lib/validate-fptf-with')
|
||||||
|
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
||||||
|
|
||||||
|
const when = createWhen(blsProfile.timezone, blsProfile.locale)
|
||||||
|
|
||||||
|
const cfg = {
|
||||||
|
when,
|
||||||
|
stationCoordsOptional: false,
|
||||||
|
products: blsProfile.products,
|
||||||
|
minLatitude: 45.3184,
|
||||||
|
minLongitude: 4.4604,
|
||||||
|
maxLatitude: 47.2969,
|
||||||
|
maxLongitude: 7.8607,
|
||||||
|
}
|
||||||
|
|
||||||
|
const validate = createValidate(cfg)
|
||||||
|
|
||||||
|
const client = createClient(blsProfile, 'public-transport/hafas-client:test')
|
||||||
|
|
||||||
|
const bernDennigkofengässli = '8590093'
|
||||||
|
|
||||||
|
tap.test('Dennigkofengässli to Schänzlihalde', async (t) => {
|
||||||
|
const schänzlihalde = {
|
||||||
|
type: 'location',
|
||||||
|
id: '990017698',
|
||||||
|
address: 'Bern, Schänzlihalde 17',
|
||||||
|
latitude: 46.952835,
|
||||||
|
longitude: 7.447527,
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await client.journeys(bernDennigkofengässli, schänzlihalde, {
|
||||||
|
results: 3,
|
||||||
|
departure: when,
|
||||||
|
})
|
||||||
|
|
||||||
|
await testJourneysStationToAddress({
|
||||||
|
test: t,
|
||||||
|
res,
|
||||||
|
validate,
|
||||||
|
fromId: bernDennigkofengässli,
|
||||||
|
to: schänzlihalde,
|
||||||
|
})
|
||||||
|
t.end()
|
||||||
|
})
|
1
test/e2e/fixtures/03cfb56ddfe0ed19d58f71b68c312c6a
vendored
Normal file
1
test/e2e/fixtures/03cfb56ddfe0ed19d58f71b68c312c6a
vendored
Normal file
File diff suppressed because one or more lines are too long
35
test/e2e/fixtures/03cfb56ddfe0ed19d58f71b68c312c6a.headers
vendored
Normal file
35
test/e2e/fixtures/03cfb56ddfe0ed19d58f71b68c312c6a.headers
vendored
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
"url": "https://bls.hafas.de/bin/mgate.exe",
|
||||||
|
"time": 1023,
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"headers": {
|
||||||
|
"Content-Type": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"Accept-Encoding": [
|
||||||
|
"gzip, br, deflate"
|
||||||
|
],
|
||||||
|
"Accept": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"user-agent": [
|
||||||
|
"pu1a6b1bee0fa6blic-transport/hafas-client:test"
|
||||||
|
],
|
||||||
|
"Content-Length": [
|
||||||
|
"706"
|
||||||
|
],
|
||||||
|
"Connection": [
|
||||||
|
"close"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -61,4 +61,5 @@ node -p "$query" "$src/de/vos-hafas-mgate.json" >../p/vos/base.json
|
||||||
node -p "$query" "$src/de/vrn-hafas-mgate.json" >../p/vrn/base.json
|
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/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/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/zvv-hafas-mgate.json" >../p/zvv/base.json
|
node -p "$query" "$src/ch/zvv-hafas-mgate.json" >../p/zvv/base.json
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 03095950efe3e938eeb262b4a79180fb9a279fb6
|
Subproject commit 14ba39a48a441e6819a7e0627d5e8701c5a0f60d
|
Loading…
Add table
Reference in a new issue