mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
temporarily use BVG endpoint
This commit is contained in:
parent
30fe3fccc3
commit
cadd4105d1
5 changed files with 40 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const formatLocationIdentifier = require('./location-identifier')
|
||||||
const formatCoord = require('./coord')
|
const formatCoord = require('./coord')
|
||||||
|
|
||||||
const formatAddress = (a) => {
|
const formatAddress = (a) => {
|
||||||
|
@ -7,13 +8,16 @@ const formatAddress = (a) => {
|
||||||
throw new Error('invalid address')
|
throw new Error('invalid address')
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const data = {
|
||||||
type: 'A',
|
A: '2', // address
|
||||||
name: a.address,
|
O: a.address,
|
||||||
crd: {
|
X: formatCoord(a.longitude),
|
||||||
x: formatCoord(a.longitude),
|
Y: formatCoord(a.latitude)
|
||||||
y: formatCoord(a.latitude)
|
|
||||||
}
|
}
|
||||||
|
if (a.id) data.L = a.id
|
||||||
|
return {
|
||||||
|
name: a.address,
|
||||||
|
lid: formatLocationIdentifier(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
format/location-identifier.js
Normal file
16
format/location-identifier.js
Normal 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
|
|
@ -1,5 +1,6 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const formatLocationIdentifier = require('./location-identifier')
|
||||||
const formatCoord = require('./coord')
|
const formatCoord = require('./coord')
|
||||||
|
|
||||||
const formatPoi = (p) => {
|
const formatPoi = (p) => {
|
||||||
|
@ -8,13 +9,14 @@ const formatPoi = (p) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'P',
|
|
||||||
name: p.name,
|
name: p.name,
|
||||||
lid: 'L=' + p.id,
|
lid: formatLocationIdentifier({
|
||||||
crd: {
|
A: '4', // POI
|
||||||
x: formatCoord(p.longitude),
|
O: p.name,
|
||||||
y: formatCoord(p.latitude)
|
X: formatCoord(p.longitude),
|
||||||
}
|
Y: formatCoord(p.latitude),
|
||||||
|
L: p.id
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,10 @@ const modes = require('./modes')
|
||||||
const formatBitmask = createFormatBitmask(modes)
|
const formatBitmask = createFormatBitmask(modes)
|
||||||
|
|
||||||
const transformReqBody = (body) => {
|
const transformReqBody = (body) => {
|
||||||
body.client = {type: 'IPA', id: 'VBB', name: 'vbbPROD', v: '4010300'}
|
body.client = {type: 'IPA', id: 'BVG', name: 'FahrInfo', v: '4070700'}
|
||||||
body.ext = 'VBB.1'
|
body.ext = 'BVG.1'
|
||||||
body.ver = '1.11' // todo: 1.16 with `mic` and `mac` query params
|
body.ver = '1.15' // todo: 1.16 with `mic` and `mac` query params
|
||||||
body.auth = {type: 'AID', aid: 'hafas-vbb-apps'}
|
body.auth = {type: 'AID', aid: '1Rxs112shyHLatUX4fofnmdxK'}
|
||||||
|
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ const formatProducts = (products) => {
|
||||||
const vbbProfile = {
|
const vbbProfile = {
|
||||||
locale: 'de-DE',
|
locale: 'de-DE',
|
||||||
timezone: 'Europe/Berlin',
|
timezone: 'Europe/Berlin',
|
||||||
endpoint: 'https://fahrinfo.vbb.de/bin/mgate.exe',
|
endpoint: 'https://bvg-apps.hafas.de/bin/mgate.exe',
|
||||||
transformReqBody,
|
transformReqBody,
|
||||||
|
|
||||||
products: modes.allProducts,
|
products: modes.allProducts,
|
||||||
|
|
|
@ -345,11 +345,11 @@ test('nearby', co(function* (t) {
|
||||||
|
|
||||||
|
|
||||||
test('locations', 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(Array.isArray(locations))
|
||||||
t.ok(locations.length > 0)
|
t.ok(locations.length > 0)
|
||||||
t.ok(locations.length <= 10)
|
t.ok(locations.length <= 20)
|
||||||
for (let l of locations) {
|
for (let l of locations) {
|
||||||
if (l.type === 'station') assertValidStation(t, l)
|
if (l.type === 'station') assertValidStation(t, l)
|
||||||
else assertValidLocation(t, l)
|
else assertValidLocation(t, l)
|
||||||
|
|
Loading…
Add table
Reference in a new issue