From cadd4105d11939ffe57031b4d7ed97d58d288900 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 15 Feb 2018 17:31:43 +0100 Subject: [PATCH] temporarily use BVG endpoint --- format/address.js | 14 +++++++++----- format/location-identifier.js | 16 ++++++++++++++++ format/poi.js | 14 ++++++++------ p/vbb/index.js | 10 +++++----- test/vbb.js | 4 ++-- 5 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 format/location-identifier.js diff --git a/format/address.js b/format/address.js index 2774c380..51e710dc 100644 --- a/format/address.js +++ b/format/address.js @@ -1,5 +1,6 @@ 'use strict' +const formatLocationIdentifier = require('./location-identifier') const formatCoord = require('./coord') const formatAddress = (a) => { @@ -7,13 +8,16 @@ const formatAddress = (a) => { throw new Error('invalid address') } + const data = { + A: '2', // address + O: a.address, + X: formatCoord(a.longitude), + Y: formatCoord(a.latitude) + } + if (a.id) data.L = a.id return { - type: 'A', name: a.address, - crd: { - x: formatCoord(a.longitude), - y: formatCoord(a.latitude) - } + lid: formatLocationIdentifier(data) } } diff --git a/format/location-identifier.js b/format/location-identifier.js new file mode 100644 index 00000000..b7529aec --- /dev/null +++ b/format/location-identifier.js @@ -0,0 +1,16 @@ +'use strict' + +const sep = '@' + +const formatLocationIdentifier = (data) => { + let str = '' + for (let key in data) { + if (!Object.prototype.hasOwnProperty.call(data, key)) continue + + str += key + '=' + data[key] + sep // todo: escape + } + + return str +} + +module.exports = formatLocationIdentifier diff --git a/format/poi.js b/format/poi.js index 3991e4c6..b1577a01 100644 --- a/format/poi.js +++ b/format/poi.js @@ -1,5 +1,6 @@ 'use strict' +const formatLocationIdentifier = require('./location-identifier') const formatCoord = require('./coord') const formatPoi = (p) => { @@ -8,13 +9,14 @@ const formatPoi = (p) => { } return { - type: 'P', name: p.name, - lid: 'L=' + p.id, - crd: { - x: formatCoord(p.longitude), - y: formatCoord(p.latitude) - } + lid: formatLocationIdentifier({ + A: '4', // POI + O: p.name, + X: formatCoord(p.longitude), + Y: formatCoord(p.latitude), + L: p.id + }) } } diff --git a/p/vbb/index.js b/p/vbb/index.js index 851647ce..6af748f0 100644 --- a/p/vbb/index.js +++ b/p/vbb/index.js @@ -20,10 +20,10 @@ const modes = require('./modes') const formatBitmask = createFormatBitmask(modes) const transformReqBody = (body) => { - body.client = {type: 'IPA', id: 'VBB', name: 'vbbPROD', v: '4010300'} - body.ext = 'VBB.1' - body.ver = '1.11' // todo: 1.16 with `mic` and `mac` query params - body.auth = {type: 'AID', aid: 'hafas-vbb-apps'} + body.client = {type: 'IPA', id: 'BVG', name: 'FahrInfo', v: '4070700'} + body.ext = 'BVG.1' + body.ver = '1.15' // todo: 1.16 with `mic` and `mac` query params + body.auth = {type: 'AID', aid: '1Rxs112shyHLatUX4fofnmdxK'} return body } @@ -167,7 +167,7 @@ const formatProducts = (products) => { const vbbProfile = { locale: 'de-DE', timezone: 'Europe/Berlin', - endpoint: 'https://fahrinfo.vbb.de/bin/mgate.exe', + endpoint: 'https://bvg-apps.hafas.de/bin/mgate.exe', transformReqBody, products: modes.allProducts, diff --git a/test/vbb.js b/test/vbb.js index e24a1ef8..8d562c81 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -345,11 +345,11 @@ test('nearby', co(function* (t) { test('locations', co(function* (t) { - const locations = yield client.locations('Alexanderplatz', {results: 10}) + const locations = yield client.locations('Alexanderplatz', {results: 20}) t.ok(Array.isArray(locations)) t.ok(locations.length > 0) - t.ok(locations.length <= 10) + t.ok(locations.length <= 20) for (let l of locations) { if (l.type === 'station') assertValidStation(t, l) else assertValidLocation(t, l)