mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
refreshJourney: return journey as field 💥✅📝
This commit is contained in:
parent
751ae21d18
commit
3cbbc3c4da
4 changed files with 11 additions and 6 deletions
|
@ -30,8 +30,10 @@ const client = createClient(vbbProfile)
|
|||
const {journeys} = await client.journeys('900000003201', '900000100008', {results: 1})
|
||||
|
||||
// later, fetch up-to-date info on the journey
|
||||
const journey = await client.refreshJourney(journeys[0].refreshToken, {stopovers: true, remarks: true})
|
||||
const {realtimeDataUpdatedAt} = journey
|
||||
const {
|
||||
journey,
|
||||
realtimeDataUpdatedAt,
|
||||
} = await client.refreshJourney(journeys[0].refreshToken, {stopovers: true, remarks: true})
|
||||
```
|
||||
|
||||
`journey` is a *single* [*Friendly Public Transport Format* v2 draft](https://github.com/public-transport/friendly-public-transport-format/blob/3bd36faa721e85d9f5ca58fb0f38cdbedb87bbca/spec/readme.md) `journey`, in the same format as returned by [`journeys()`](journeys.md).
|
||||
|
|
2
index.js
2
index.js
|
@ -262,10 +262,10 @@ const createClient = (profile, userAgent, opt = {}) => {
|
|||
const ctx = {profile, opt, common, res}
|
||||
|
||||
return {
|
||||
journey: profile.parseJourney(ctx, res.outConL[0]),
|
||||
realtimeDataUpdatedAt: res.planrtTS && res.planrtTS !== '0'
|
||||
? parseInt(res.planrtTS)
|
||||
: null,
|
||||
...profile.parseJourney(ctx, res.outConL[0])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,10 +32,11 @@ const testRefreshJourney = async (cfg) => {
|
|||
t.equal(typeof model.refreshToken, 'string')
|
||||
t.ok(model.refreshToken)
|
||||
|
||||
const refreshed = await refreshJourney(model.refreshToken, {
|
||||
const refreshedRes = await refreshJourney(model.refreshToken, {
|
||||
stopovers: false
|
||||
})
|
||||
validate(t, refreshed, 'refreshJourneyResult', 'refreshed')
|
||||
validate(t, refreshedRes, 'refreshJourneyResult', 'refreshedRes')
|
||||
const refreshed = refreshedRes.journey
|
||||
|
||||
t.same(simplify(refreshed), simplify(model))
|
||||
}
|
||||
|
|
|
@ -433,9 +433,11 @@ const validateJourneysResult = (val, res, name = 'journeysResult') => {
|
|||
}
|
||||
|
||||
const validateRefreshJourneyResult = (val, res, name = 'refreshJourneyResult') => {
|
||||
val.journey(val, res, name + '.journey')
|
||||
a.ok(isObj(res), name + ' must be an object')
|
||||
|
||||
val.realtimeDataUpdatedAt(val, res.realtimeDataUpdatedAt, name + '.realtimeDataUpdatedAt')
|
||||
|
||||
val.journey(val, res.journey, name + '.journey')
|
||||
}
|
||||
|
||||
const validateTrip = (val, trip, name = 'trip') => {
|
||||
|
|
Loading…
Add table
Reference in a new issue