mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
radar: realtimeDataFrom -> realtimeDataUpdatedAt 💥✅📝
This commit is contained in:
parent
a6411707e1
commit
0cc50a918a
28 changed files with 76 additions and 56 deletions
|
@ -30,7 +30,10 @@ const vbbProfile = require('hafas-client/p/vbb')
|
|||
|
||||
const client = createClient(vbbProfile, 'my-awesome-program')
|
||||
|
||||
await client.radar({
|
||||
const {
|
||||
movements,
|
||||
realtimeDataUpdatedAt,
|
||||
} = await client.radar({
|
||||
north: 52.52411,
|
||||
west: 13.41002,
|
||||
south: 52.51942,
|
||||
|
@ -38,7 +41,9 @@ await client.radar({
|
|||
}, {results: 5})
|
||||
```
|
||||
|
||||
The result may look like this:
|
||||
`realtimeDataUpdatedAt` is a UNIX timestamp reflecting the latest moment when (at least some of) the response's realtime data have been updated.
|
||||
|
||||
`movements` may look like this:
|
||||
|
||||
```js
|
||||
[ {
|
||||
|
|
10
index.js
10
index.js
|
@ -619,8 +619,14 @@ const createClient = (profile, userAgent, opt = {}) => {
|
|||
if (!Array.isArray(res.jnyL)) return []
|
||||
const ctx = {profile, opt, common, res}
|
||||
|
||||
// todo [breaking]: return object with realtimeDataUpdatedAt
|
||||
return res.jnyL.map(m => profile.parseMovement(ctx, m))
|
||||
const movements = res.jnyL.map(m => profile.parseMovement(ctx, m))
|
||||
|
||||
return {
|
||||
movements,
|
||||
realtimeDataUpdatedAt: res.planrtTS && res.planrtTS !== '0'
|
||||
? parseInt(res.planrtTS)
|
||||
: null,
|
||||
}
|
||||
}
|
||||
|
||||
const reachableFrom = async (address, opt = {}) => {
|
||||
|
|
|
@ -416,7 +416,7 @@ tap.test('stop', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 52.52411,
|
||||
west: 13.41002,
|
||||
south: 52.51942,
|
||||
|
@ -425,7 +425,7 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ tap.test('stop Mersch', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 49.9,
|
||||
west: 6.05,
|
||||
south: 49.8,
|
||||
|
@ -266,6 +266,6 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
|
|
@ -235,7 +235,7 @@ tap.test('station Domain', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 30.240877,
|
||||
west: -97.804588,
|
||||
south: 30.225378,
|
||||
|
@ -244,7 +244,7 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ tap.test('station Hagen-Vorhalle', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 51.5,
|
||||
west: 7.2,
|
||||
south: 51.2,
|
||||
|
@ -136,6 +136,6 @@ tap.test('radar', async (t) => {
|
|||
...cfg,
|
||||
stationCoordsOptional: true,
|
||||
}, {})
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
|
|
@ -445,7 +445,7 @@ tap.test('line with additionalName', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 52.52411,
|
||||
west: 13.41002,
|
||||
south: 52.51942,
|
||||
|
@ -454,7 +454,7 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ tap.skip('station Hamburg Barmbek', async (t) => {
|
|||
})
|
||||
|
||||
tap.skip('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 53.569,
|
||||
west: 10.022,
|
||||
south: 53.55,
|
||||
|
@ -247,6 +247,6 @@ tap.skip('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
|
|
@ -279,7 +279,7 @@ tap.test('station Magdeburg-Buckau', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 52.148364,
|
||||
west: 11.600826,
|
||||
south: 52.108486,
|
||||
|
@ -292,7 +292,7 @@ tap.test('radar', async (t) => {
|
|||
stationCoordsOptional: true, // see #28
|
||||
})
|
||||
const validate = createValidate(customCfg, validators)
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
|
|
@ -279,7 +279,7 @@ tap.test('stop Ettinger Str.', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 48.74453,
|
||||
west: 11.42733,
|
||||
south: 48.73453,
|
||||
|
@ -288,6 +288,6 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
|
|
@ -632,6 +632,14 @@ const validateMovements = (val, ms, name = 'movements') => {
|
|||
}
|
||||
}
|
||||
|
||||
const validateRadarResult = (val, res, name = 'movementsResult') => {
|
||||
a.ok(isObj(res), name + ' must be an object')
|
||||
|
||||
val.movements(val, res.movements, name + '.movements')
|
||||
|
||||
val.realtimeDataUpdatedAt(val, res.realtimeDataUpdatedAt, name + '.realtimeDataUpdatedAt')
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
realtimeDataUpdatedAt: createValidateRealtimeDataUpdatedAt,
|
||||
products: createValidateProducts,
|
||||
|
@ -660,5 +668,6 @@ module.exports = {
|
|||
arrivalsResponse: createValidateArrivalsResponse,
|
||||
departuresResponse: createValidateDeparturesResponse,
|
||||
movement: createValidateMovement,
|
||||
movements: () => validateMovements
|
||||
movements: () => validateMovements,
|
||||
radarResult: () => validateRadarResult,
|
||||
}
|
||||
|
|
|
@ -236,7 +236,7 @@ tap.test('station Aachen Hbf', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 51.4358,
|
||||
west: 6.7625,
|
||||
south: 51.4214,
|
||||
|
@ -245,7 +245,7 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10,
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -260,7 +260,7 @@ tap.test('stop Mersch', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 49.9,
|
||||
west: 6.05,
|
||||
south: 49.8,
|
||||
|
@ -269,6 +269,6 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
|
|
@ -330,7 +330,7 @@ tap.test('stop', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 54.4,
|
||||
west: 10.0,
|
||||
south: 54.2,
|
||||
|
@ -351,7 +351,7 @@ tap.test('radar', async (t) => {
|
|||
validateStation(validate, s, name)
|
||||
}
|
||||
})
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
|
|
@ -253,7 +253,7 @@ tap.test('station Auestadion', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 51.320153,
|
||||
west: 9.458359,
|
||||
south: 51.304304,
|
||||
|
@ -262,7 +262,7 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
|
|
@ -367,7 +367,7 @@ tap.test('stop', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar Salzburg', async (t) => {
|
||||
let vehicles = await client.radar({
|
||||
let res = await client.radar({
|
||||
north: 47.827203,
|
||||
west: 13.001261,
|
||||
south: 47.773278,
|
||||
|
@ -377,7 +377,7 @@ tap.test('radar Salzburg', async (t) => {
|
|||
})
|
||||
|
||||
// todo: find a way to always get frames from the API
|
||||
vehicles = vehicles.filter(m => m.frames && m.frames.length > 0)
|
||||
res.movements = res.movements.filter(m => m.frames && m.frames.length > 0)
|
||||
|
||||
// todo: find a way to always get products from the API
|
||||
// todo: cfg.stationProductsOptional option
|
||||
|
@ -396,7 +396,7 @@ tap.test('radar Salzburg', async (t) => {
|
|||
}, name)
|
||||
},
|
||||
})
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
|
|
@ -131,7 +131,7 @@ tap.skip('nearby', async (t) => {
|
|||
})
|
||||
|
||||
tap.skip('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 48.74453,
|
||||
west: 11.42733,
|
||||
south: 48.73453,
|
||||
|
@ -140,7 +140,7 @@ tap.skip('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -184,7 +184,7 @@ tap.test('stop Næstved', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 55.695,
|
||||
west: 12.498,
|
||||
south: 55.639,
|
||||
|
@ -193,6 +193,6 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10,
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
|
|
@ -83,7 +83,7 @@ tap.test('arrivals at Wiesbaden Hbf', async (t) => {
|
|||
// todo: nearby
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 53.090516,
|
||||
west: 8.750106,
|
||||
south: 53.062859,
|
||||
|
@ -92,7 +92,7 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ tap.test('arrivals at Platz der Jugend', async (t) => {
|
|||
// todo: nearby
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 54.116968,
|
||||
west: 12.029738,
|
||||
south: 54.060517,
|
||||
|
@ -109,7 +109,7 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ tap.test('stop', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 49.27,
|
||||
west: 6.97,
|
||||
south: 49.22,
|
||||
|
@ -278,6 +278,6 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
|
|
@ -252,7 +252,7 @@ tap.test('station Karl-Theodor-Straße', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 48.145121,
|
||||
west: 11.543736,
|
||||
south: 48.138339,
|
||||
|
@ -261,7 +261,7 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ tap.test('arrivals at Bruxelles Midi', async (t) => {
|
|||
// todo: nearby
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 51.065,
|
||||
west: 3.688,
|
||||
south: 51.04,
|
||||
|
@ -97,7 +97,7 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -402,7 +402,7 @@ tap.test('stop', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 52.52411,
|
||||
west: 13.41002,
|
||||
south: 52.51942,
|
||||
|
@ -411,7 +411,7 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ tap.test('arrivals at Bremen Humboldtstr.', async (t) => {
|
|||
// todo: nearby
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 53.090516,
|
||||
west: 8.750106,
|
||||
south: 53.062859,
|
||||
|
@ -92,7 +92,7 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ tap.test('station Meckesheim', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 49.4940,
|
||||
west: 8.4560,
|
||||
south: 49.4774,
|
||||
|
@ -226,6 +226,6 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10,
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
|
|
@ -169,7 +169,7 @@ tap.test('stop Jugendherberge', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 52,
|
||||
west: 9.8,
|
||||
south: 51.51,
|
||||
|
@ -177,6 +177,6 @@ tap.test('radar', async (t) => {
|
|||
}, {
|
||||
duration: 5 * 60, when, results: 10
|
||||
})
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
|
|
@ -114,7 +114,7 @@ tap.test('locations named Rennweg', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('radar', async (t) => {
|
||||
const vehicles = await client.radar({
|
||||
const res = await client.radar({
|
||||
north: 47.387,
|
||||
west: 8.514,
|
||||
south: 47.356,
|
||||
|
@ -123,6 +123,6 @@ tap.test('radar', async (t) => {
|
|||
duration: 5 * 60, when, results: 10,
|
||||
})
|
||||
|
||||
validate(t, vehicles, 'movements', 'vehicles')
|
||||
validate(t, res, 'radarResult', 'res')
|
||||
t.end()
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue