temporarily use BVG endpoint

This commit is contained in:
Jannis R 2018-02-15 17:31:43 +01:00
parent 30fe3fccc3
commit cadd4105d1
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
5 changed files with 40 additions and 18 deletions

View file

@ -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)
}
}

View file

@ -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

View file

@ -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
})
}
}

View file

@ -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,

View file

@ -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)