mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
move refreshJourneyReq-formatter to own function
This commit is contained in:
parent
542a9eea02
commit
1c67350b48
5 changed files with 40 additions and 10 deletions
18
format/refresh-journey-req.js
Normal file
18
format/refresh-journey-req.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
'use strict'
|
||||
|
||||
const formatRefreshJourneyReq = (ctx, refreshToken) => {
|
||||
const {profile, opt} = ctx
|
||||
|
||||
return {
|
||||
meth: 'Reconstruction',
|
||||
req: {
|
||||
ctxRecon: refreshToken,
|
||||
getIST: true, // todo: make an option
|
||||
getPasslist: !!opt.stopovers,
|
||||
getPolyline: !!opt.polylines,
|
||||
getTariff: !!opt.tickets
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = formatRefreshJourneyReq
|
13
index.js
13
index.js
|
@ -249,16 +249,9 @@ const createClient = (profile, userAgent, opt = {}) => {
|
|||
remarks: true // parse & expose hints & warnings?
|
||||
}, opt)
|
||||
|
||||
return profile.request({profile, opt}, userAgent, {
|
||||
meth: 'Reconstruction',
|
||||
req: {
|
||||
ctxRecon: refreshToken,
|
||||
getIST: true, // todo: make an option
|
||||
getPasslist: !!opt.stopovers,
|
||||
getPolyline: !!opt.polylines,
|
||||
getTariff: !!opt.tickets
|
||||
}
|
||||
})
|
||||
const req = profile.formatRefreshJourneyReq({profile, opt}, refreshToken)
|
||||
|
||||
return profile.request({profile, opt}, userAgent, req)
|
||||
.then(({res, common}) => {
|
||||
if (!Array.isArray(res.outConL) || !res.outConL[0]) {
|
||||
throw new Error('invalid response')
|
||||
|
|
|
@ -9,6 +9,7 @@ const formatNearbyReq = require('../format/nearby-req')
|
|||
const formatTripReq = require('../format/trip-req')
|
||||
const formatRadarReq = require('../format/radar-req')
|
||||
const formatReachableFromReq = require('../format/reachable-from-req')
|
||||
const formatRefreshJourneyReq = require('../format/refresh-journey-req')
|
||||
|
||||
const parseDateTime = require('../parse/date-time')
|
||||
const parsePlatform = require('../parse/platform')
|
||||
|
@ -59,6 +60,7 @@ const defaultProfile = {
|
|||
formatTripReq,
|
||||
formatRadarReq,
|
||||
formatReachableFromReq,
|
||||
formatRefreshJourneyReq,
|
||||
transformJourneysQuery: id,
|
||||
|
||||
parseDateTime,
|
||||
|
|
|
@ -15,6 +15,7 @@ const types = {
|
|||
formatTripReq: 'function',
|
||||
formatRadarReq: 'function',
|
||||
formatReachableFromReq: 'function',
|
||||
formatRefreshJourneyReq: 'function',
|
||||
transformJourneysQuery: 'function',
|
||||
|
||||
products: 'array',
|
||||
|
|
|
@ -11,6 +11,21 @@ const transformReqBody = (ctx, body) => {
|
|||
return body
|
||||
}
|
||||
|
||||
const formatRefreshJourneyReq = (ctx, refreshToken) => {
|
||||
const {profile, opt} = ctx
|
||||
|
||||
return {
|
||||
meth: 'Reconstruction',
|
||||
req: {
|
||||
outReconL: [{ctx: refreshToken}],
|
||||
getIST: true, // todo: make an option
|
||||
getPasslist: !!opt.stopovers,
|
||||
getPolyline: !!opt.polylines,
|
||||
getTariff: !!opt.tickets
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const vsnProfile = {
|
||||
locale: 'de-DE',
|
||||
timezone: 'Europe/Berlin',
|
||||
|
@ -22,6 +37,7 @@ const vsnProfile = {
|
|||
addMicMac: true,
|
||||
|
||||
transformReqBody,
|
||||
formatRefreshJourneyReq,
|
||||
|
||||
products: products,
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue