mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
reachableFrom: realtimeDataFrom -> realtimeDataUpdatedAt 💥✅📝
This commit is contained in:
parent
0cc50a918a
commit
2fcaa2304b
4 changed files with 24 additions and 6 deletions
|
@ -36,17 +36,22 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
|
|
||||||
const client = createClient(vbbProfile, 'my-awesome-program')
|
const client = createClient(vbbProfile, 'my-awesome-program')
|
||||||
|
|
||||||
console.log(await client.reachableFrom({
|
const {
|
||||||
|
reachable,
|
||||||
|
realtimeDataUpdatedAt,
|
||||||
|
} = await client.reachableFrom({
|
||||||
type: 'location',
|
type: 'location',
|
||||||
address: '13353 Berlin-Wedding, Torfstr. 17',
|
address: '13353 Berlin-Wedding, Torfstr. 17',
|
||||||
latitude: 52.541797,
|
latitude: 52.541797,
|
||||||
longitude: 13.350042
|
longitude: 13.350042
|
||||||
}, {
|
}, {
|
||||||
maxDuration: 10 // minutes
|
maxDuration: 10 // minutes
|
||||||
}))
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
`reachable` may look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
[
|
[
|
||||||
|
|
8
index.js
8
index.js
|
@ -669,8 +669,12 @@ const createClient = (profile, userAgent, opt = {}) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo [breaking]: return object with realtimeDataUpdatedAt
|
return {
|
||||||
return byDuration
|
reachable: byDuration,
|
||||||
|
realtimeDataUpdatedAt: res.planrtTS && res.planrtTS !== '0'
|
||||||
|
? parseInt(res.planrtTS)
|
||||||
|
: null,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const remarks = async (opt = {}) => {
|
const remarks = async (opt = {}) => {
|
||||||
|
|
|
@ -12,9 +12,17 @@ const testReachableFrom = async (cfg) => {
|
||||||
validate
|
validate
|
||||||
} = cfg
|
} = cfg
|
||||||
|
|
||||||
const results = await reachableFrom(address, {
|
const res = await reachableFrom(address, {
|
||||||
when, maxDuration
|
when, maxDuration
|
||||||
})
|
})
|
||||||
|
const {
|
||||||
|
reachable: results,
|
||||||
|
realtimeDataUpdatedAt,
|
||||||
|
} = res
|
||||||
|
|
||||||
|
if (realtimeDataUpdatedAt !== null) { // todo: move this check into validators
|
||||||
|
validate(t, realtimeDataUpdatedAt, 'realtimeDataUpdatedAt', 'res.realtimeDataUpdatedAt')
|
||||||
|
}
|
||||||
|
|
||||||
t.ok(Array.isArray(results), 'results must an array')
|
t.ok(Array.isArray(results), 'results must an array')
|
||||||
t.ok(results.length > 0, 'results must have >0 items')
|
t.ok(results.length > 0, 'results must have >0 items')
|
||||||
|
|
|
@ -13,6 +13,7 @@ const is = val => val !== null && val !== undefined
|
||||||
|
|
||||||
const createValidateRealtimeDataUpdatedAt = (cfg) => {
|
const createValidateRealtimeDataUpdatedAt = (cfg) => {
|
||||||
const validateRealtimeDataUpdatedAt = (val, rtDataUpdatedAt, name = 'realtimeDataUpdatedAt') => {
|
const validateRealtimeDataUpdatedAt = (val, rtDataUpdatedAt, name = 'realtimeDataUpdatedAt') => {
|
||||||
|
a.ok(Number.isInteger(rtDataUpdatedAt), name + ' must be an integer')
|
||||||
assertValidWhen(rtDataUpdatedAt * 1000, cfg.when, name, 100 * DAY)
|
assertValidWhen(rtDataUpdatedAt * 1000, cfg.when, name, 100 * DAY)
|
||||||
}
|
}
|
||||||
return validateRealtimeDataUpdatedAt
|
return validateRealtimeDataUpdatedAt
|
||||||
|
|
Loading…
Add table
Reference in a new issue