mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
add DART profile 📝✅
This commit is contained in:
parent
182a0797e7
commit
042668ff56
10 changed files with 188 additions and 1 deletions
14
p/dart/base.json
Normal file
14
p/dart/base.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"auth": {
|
||||
"type": "AID",
|
||||
"aid": "XNFGL2aSkxfDeK8N4waOZnsdJ"
|
||||
},
|
||||
"client": {
|
||||
"type": "WEB",
|
||||
"id": "DART",
|
||||
"name": "webapp"
|
||||
},
|
||||
"endpoint": "https://dart.hafas.de/bin/mgate.exe",
|
||||
"ver": "1.35",
|
||||
"defaultLanguage": "en"
|
||||
}
|
54
p/dart/example.js
Normal file
54
p/dart/example.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
'use strict'
|
||||
|
||||
const createClient = require('../..')
|
||||
const dartProfile = require('.')
|
||||
|
||||
const client = createClient(dartProfile, 'hafas-client example')
|
||||
|
||||
const mlkJrPkwyAdamsAveDsm2055 = '100002702'
|
||||
const se5thStEHackleyAveDsm2294 = '100004972'
|
||||
|
||||
// client.journeys(mlkJrPkwyAdamsAveDsm2055, se5thStEHackleyAveDsm2294, {
|
||||
// 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.find(l => !!l.line)
|
||||
// return client.trip(leg.tripId, leg.line.name, {polyline: true})
|
||||
// })
|
||||
|
||||
// client.departures(mlkJrPkwyAdamsAveDsm2055, {duration: 10})
|
||||
// client.arrivals(mlkJrPkwyAdamsAveDsm2055, {linesOfStops: true})
|
||||
|
||||
client.locations('adams ave', {results: 3})
|
||||
// client.stop(mlkJrPkwyAdamsAveDsm2055, {linesOfStops: true})
|
||||
// client.nearby({
|
||||
// type: 'location',
|
||||
// id: '980010311',
|
||||
// address: 'Austraße 37, 6700 Bludenz',
|
||||
// latitude: 41.6056,
|
||||
// longitude: -93.5916,
|
||||
// }, {distance: 1000})
|
||||
// client.reachableFrom({
|
||||
// type: 'location',
|
||||
// latitude: 41.613584,
|
||||
// longitude: -93.881803,
|
||||
// address: 'Laurel St, Waukee, 50263',
|
||||
// }, {
|
||||
// maxDuration: 20,
|
||||
// })
|
||||
// client.radar({
|
||||
// north: 41.6266,
|
||||
// west: -93.7299,
|
||||
// south: 41.5503,
|
||||
// east: -93.5699,
|
||||
// })
|
||||
|
||||
.then((data) => {
|
||||
console.log(require('util').inspect(data, {depth: null, colors: true}))
|
||||
})
|
||||
.catch(console.error)
|
29
p/dart/index.js
Normal file
29
p/dart/index.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
'use strict'
|
||||
|
||||
const baseProfile = require('./base.json')
|
||||
|
||||
const products = [{
|
||||
id: 'bus',
|
||||
mode: 'bus',
|
||||
bitmasks: [32],
|
||||
name: 'Bus',
|
||||
short: 'Bus',
|
||||
default: true,
|
||||
}]
|
||||
|
||||
const dartProfile = {
|
||||
...baseProfile,
|
||||
locale: 'en-US',
|
||||
timezone: 'America/Chicago',
|
||||
|
||||
products,
|
||||
|
||||
departuresGetPasslist: false,
|
||||
departuresStbFltrEquiv: false,
|
||||
refreshJourneyUseOutReconL: true,
|
||||
trip: true,
|
||||
reachableFrom: true,
|
||||
radar: true,
|
||||
}
|
||||
|
||||
module.exports = dartProfile
|
17
p/dart/readme.md
Normal file
17
p/dart/readme.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
# DART profile for `hafas-client`
|
||||
|
||||
[*Des Moines Area Rapid Transit (DART)*](https://en.wikipedia.org/wiki/Des_Moines_Area_Regional_Transit) is the local transport provider of [Des Moines](https://en.wikipedia.org/wiki/Des_Moines_metropolitan_area), Iowa, USA. This profile adds *DART* support to `hafas-client`.
|
||||
|
||||
*Note:* This profile *does not* support [*Dallas Area Rapid Transit (DART)*](https://de.wikipedia.org/wiki/Verkehrsverbund_Vorarlberg) in [Dallas–Fort Worth](https://en.wikipedia.org/wiki/Dallas–Fort_Worth_metroplex), Texas, USA.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const createClient = require('hafas-client')
|
||||
const dartProfile = require('hafas-client/p/dart')
|
||||
|
||||
// create a client with DART profile
|
||||
const client = createClient(dartProfile, 'my-awesome-program')
|
||||
```
|
||||
|
||||
Check out the [code examples](example.js).
|
|
@ -18,6 +18,7 @@ HAFAS endpoint | wrapper library | docs | example code | profile name
|
|||
[Österreichische Bundesbahnen (ÖBB)](https://en.wikipedia.org/wiki/Austrian_Federal_Railways) | [`oebb-hafas`](https://github.com/juliuste/oebb-hafas) | [docs](oebb/readme.md) | [example](oebb/example.js) | [`oebb`](oebb)
|
||||
[*Mobilitéitszentral* (Luxembourg)](https://www.mobiliteit.lu/) | - | [docs](mobiliteit-lu/readme.md) | [example](mobiliteit-lu/example.js) | [`mobiliteit-lu`](mobiliteit-lu)
|
||||
[Bay Area Rapid Transit (BART)](https://en.wikipedia.org/wiki/Bay_Area_Rapid_Transit) | - | [docs](bart/readme.md) | [example](bart/example.js) | [`bart`](bart)
|
||||
[Des Moines Area Rapid Transit (DART)](https://en.wikipedia.org/wiki/Des_Moines_metropolitan_area) | - | [docs](dart/readme.md) | [example](dart/example.js) | [`dart`](dart)
|
||||
[Nahverkehr Sachsen-Anhalt (NASA)](https://de.wikipedia.org/wiki/Nahverkehrsservice_Sachsen-Anhalt)/[INSA](https://insa.de) | [`insa-hafas`](https://github.com/public-transport/insa-hafas) | [docs](insa/readme.md) | [example](insa/example.js) | [`insa`](insa)
|
||||
[Nahverkehrsverbund Schleswig-Holstein (NAH.SH)](https://de.wikipedia.org/wiki/Nahverkehrsverbund_Schleswig-Holstein) | [`nahsh-hafas`](https://github.com/juliuste/nahsh-hafas) | [docs](nahsh/readme.md) | [example](nahsh/example.js) | [`nahsh`](nahsh)
|
||||
[Rhein-Main-Verkehrsverbund (RMV)](https://en.wikipedia.org/wiki/Rhein-Main-Verkehrsverbund) | - | [docs](rmv/readme.md) | [example](rmv/example.js) | [`rmv`](rmv)
|
||||
|
|
35
test/e2e/dart.js
Normal file
35
test/e2e/dart.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
'use strict'
|
||||
|
||||
const tap = require('tap')
|
||||
|
||||
const {createWhen} = require('./lib/util')
|
||||
const createClient = require('../..')
|
||||
const dartProfile = require('../../p/dart')
|
||||
const createValidate = require('./lib/validate-fptf-with')
|
||||
|
||||
const when = createWhen(dartProfile.timezone, dartProfile.locale)
|
||||
const cfg = {
|
||||
when,
|
||||
stationCoordsOptional: false,
|
||||
products: dartProfile.products,
|
||||
maxLatitude: 45.391,
|
||||
maxLongitude: -88.176,
|
||||
minLatitude: 37.745,
|
||||
minLongitude: -96.877,
|
||||
}
|
||||
const validate = createValidate(cfg)
|
||||
|
||||
const client = createClient(dartProfile, 'public-transport/hafas-client:test')
|
||||
|
||||
const mlkJrParkwayAdamsAve = '951013488' // MARTIN LUTHER KING JR PKWY/ADAMS AVE
|
||||
|
||||
tap.test('locations named "martin luther kind adams"', async (t) => {
|
||||
const locations = await client.locations('martin luther kind adams')
|
||||
|
||||
validate(t, locations, 'locations', 'locations')
|
||||
t.ok(locations.some((l) => {
|
||||
return l.station && l.station.id === mlkJrParkwayAdamsAve || l.id === mlkJrParkwayAdamsAve
|
||||
}), '"MARTIN LUTHER KING JR PKWY/ADAMS AVE" not found')
|
||||
|
||||
t.end()
|
||||
})
|
1
test/e2e/fixtures/d0726058b4c6c86d4efc9b4bf5c1b8bd
vendored
Normal file
1
test/e2e/fixtures/d0726058b4c6c86d4efc9b4bf5c1b8bd
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"ver":"1.35","lang":"eng","id":"yj645kq46iwzpgwx","err":"OK","graph":{"id":"standard","index":0},"subGraph":{"id":"global","index":0},"view":{"id":"standard","index":0,"type":"WGS84"},"svcResL":[{"meth":"LocMatch","err":"OK","res":{"common":{"icoL":[{"res":"POI"}]},"match":{"field":"S","state":"L","locL":[{"lid":"A=4@O=MARTIN LUTHER KING JR PKWY/ADAMS AVE@X=-93648677@Y=41621818@U=102@L=951013488@B=1@p=1515749769@","type":"P","name":"MARTIN LUTHER KING JR PKWY/ADAMS AVE","icoX":0,"extId":"951013488","state":"F","crd":{"x":-93648677,"y":41621818,"floor":0}},{"lid":"A=4@O=MARTIN LUTHER KING JR PKWY/MONDAMIN AVE@X=-93643840@Y=41608253@U=102@L=951013511@B=1@p=1515749769@","type":"P","name":"MARTIN LUTHER KING JR PKWY/MONDAMIN AVE","icoX":0,"extId":"951013511","state":"F","crd":{"x":-93643840,"y":41608253,"floor":0}},{"lid":"A=4@O=MARTIN LUTHER KING JR PKWY/MARTIN LUTHER KING JR PKWY@X=-93651472@Y=41627724@U=102@L=951013492@B=1@p=1515749769@","type":"P","name":"MARTIN LUTHER KING JR PKWY/MARTIN LUTHER KING JR PKWY","icoX":0,"extId":"951013492","state":"F","crd":{"x":-93651472,"y":41627724,"floor":0}},{"lid":"A=4@O=MARTIN LUTHER KING JR PKWY/ALLISON AVE@X=-93645306@Y=41612172@U=102@L=951013490@B=1@p=1515749769@","type":"P","name":"MARTIN LUTHER KING JR PKWY/ALLISON AVE","icoX":0,"extId":"951013490","state":"F","crd":{"x":-93645306,"y":41612172,"floor":0}},{"lid":"A=4@O=MARTIN LUTHER KING JR PKWY/ATKINS ST@X=-93643813@Y=41597439@U=102@L=951013498@B=1@p=1515749769@","type":"P","name":"MARTIN LUTHER KING JR PKWY/ATKINS ST","icoX":0,"extId":"951013498","state":"F","crd":{"x":-93643813,"y":41597439,"floor":0}}]}}}]}
|
35
test/e2e/fixtures/d0726058b4c6c86d4efc9b4bf5c1b8bd.headers
vendored
Normal file
35
test/e2e/fixtures/d0726058b4c6c86d4efc9b4bf5c1b8bd.headers
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"statusCode": 200,
|
||||
"headers": {
|
||||
"date": "Mon, 13 Sep 2021 12:18:38 GMT",
|
||||
"server": "Apache",
|
||||
"content-length": "523",
|
||||
"connection": "close",
|
||||
"content-type": "application/json; charset=utf-8"
|
||||
},
|
||||
"url": "https://dart.hafas.de/bin/mgate.exe",
|
||||
"time": 313,
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"headers": {
|
||||
"Content-Type": [
|
||||
"application/json"
|
||||
],
|
||||
"Accept-Encoding": [
|
||||
"gzip, br, deflate"
|
||||
],
|
||||
"Accept": [
|
||||
"application/json"
|
||||
],
|
||||
"user-agent": [
|
||||
"public-transpora18c8e04dc29t/hafas-client:test"
|
||||
],
|
||||
"Content-Length": [
|
||||
"287"
|
||||
],
|
||||
"Connection": [
|
||||
"close"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -70,3 +70,4 @@ node -p "$query" "$src/at/vvv-hafas-mgate.json" >../p/vvv/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
|
||||
node -p "$query" "$src/us/dart-hafas-mgate.json" >../p/dart/base.json
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit f297b865747394b3d797e8eaa06b11006ad5d987
|
||||
Subproject commit 023caad70f42e808189a6d3e1b6fcaef47ce870c
|
Loading…
Add table
Reference in a new issue