diff --git a/p/dart/base.json b/p/dart/base.json new file mode 100644 index 00000000..08b0eedc --- /dev/null +++ b/p/dart/base.json @@ -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" +} diff --git a/p/dart/example.js b/p/dart/example.js new file mode 100644 index 00000000..1d8c5995 --- /dev/null +++ b/p/dart/example.js @@ -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) diff --git a/p/dart/index.js b/p/dart/index.js new file mode 100644 index 00000000..aa77a6d7 --- /dev/null +++ b/p/dart/index.js @@ -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 diff --git a/p/dart/readme.md b/p/dart/readme.md new file mode 100644 index 00000000..c77666a1 --- /dev/null +++ b/p/dart/readme.md @@ -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). diff --git a/p/readme.md b/p/readme.md index 58ee47a8..dbc7d732 100644 --- a/p/readme.md +++ b/p/readme.md @@ -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) diff --git a/test/e2e/dart.js b/test/e2e/dart.js new file mode 100644 index 00000000..34fc9fe5 --- /dev/null +++ b/test/e2e/dart.js @@ -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() +}) diff --git a/test/e2e/fixtures/d0726058b4c6c86d4efc9b4bf5c1b8bd b/test/e2e/fixtures/d0726058b4c6c86d4efc9b4bf5c1b8bd new file mode 100644 index 00000000..6074619c --- /dev/null +++ b/test/e2e/fixtures/d0726058b4c6c86d4efc9b4bf5c1b8bd @@ -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}}]}}}]} \ No newline at end of file diff --git a/test/e2e/fixtures/d0726058b4c6c86d4efc9b4bf5c1b8bd.headers b/test/e2e/fixtures/d0726058b4c6c86d4efc9b4bf5c1b8bd.headers new file mode 100644 index 00000000..b96b01e0 --- /dev/null +++ b/test/e2e/fixtures/d0726058b4c6c86d4efc9b4bf5c1b8bd.headers @@ -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" + ] + } + } +} \ No newline at end of file diff --git a/tools/pull-profile-base-data.sh b/tools/pull-profile-base-data.sh index be4503dc..47ca65d7 100755 --- a/tools/pull-profile-base-data.sh +++ b/tools/pull-profile-base-data.sh @@ -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 diff --git a/tools/transport-apis b/tools/transport-apis index f297b865..023caad7 160000 --- a/tools/transport-apis +++ b/tools/transport-apis @@ -1 +1 @@ -Subproject commit f297b865747394b3d797e8eaa06b11006ad5d987 +Subproject commit 023caad70f42e808189a6d3e1b6fcaef47ce870c