support pricing information

This commit is contained in:
Julius Tens 2018-03-15 09:33:31 +01:00
parent b8bf680295
commit 2aa9dfdd45
2 changed files with 46 additions and 1 deletions

View file

@ -6,7 +6,7 @@ const nahshProfile = require('.')
const client = createClient(nahshProfile) const client = createClient(nahshProfile)
// Flensburg Hbf to Kiel Hbf // Flensburg Hbf to Kiel Hbf
client.journeys('8000103', '8000199', {results: 10}) client.journeys('8000103', '8000199', {results: 10, tickets: true})
// client.departures('8000199', {duration: 10}) // client.departures('8000199', {duration: 10})
// client.journeyLeg('1|30161|5|100|14032018', 'Bus 52') // client.journeyLeg('1|30161|5|100|14032018', 'Bus 52')
// client.locations('Schleswig', {results: 1}) // client.locations('Schleswig', {results: 1})

View file

@ -4,6 +4,7 @@ const createParseBitmask = require('../../parse/products-bitmask')
const createFormatBitmask = require('../../format/products-bitmask') const createFormatBitmask = require('../../format/products-bitmask')
const _createParseLine = require('../../parse/line') const _createParseLine = require('../../parse/line')
const _parseLocation = require('../../parse/location') const _parseLocation = require('../../parse/location')
const _createParseJourney = require('../../parse/journey')
const products = require('./products') const products = require('./products')
@ -62,6 +63,49 @@ const createParseLine = (profile, operators) => {
return parseLineWithMode return parseLineWithMode
} }
const createParseJourney = (profile, stations, lines, remarks) => {
const parseJourney = _createParseJourney(profile, stations, lines, remarks)
const parseJourneyWithTickets = (j) => {
const res = parseJourney(j)
if (
j.trfRes &&
Array.isArray(j.trfRes.fareSetL) &&
j.trfRes.fareSetL.length > 0
) {
res.tickets = []
for(let t of j.trfRes.fareSetL){
const tariff = t.desc
if(!tariff || !Array.isArray(t.fareL)) continue
for(let v of t.fareL){
const variant = v.name
if(!variant) continue
const ticket = {
name: [tariff, variant].join(' - '),
tariff,
variant
}
if(v.prc && Number.isInteger(v.prc) && v.cur){
ticket.amount = v.prc/100
ticket.currency = v.cur
}
else{
ticket.amount = null
ticket.hint = 'No pricing information available.'
}
res.tickets.push(ticket)
}
}
}
return res
}
return parseJourneyWithTickets
}
const defaultProducts = { const defaultProducts = {
nationalExp: true, nationalExp: true,
national: true, national: true,
@ -95,6 +139,7 @@ const nahshProfile = {
parseProducts: createParseBitmask(products.allProducts, defaultProducts), parseProducts: createParseBitmask(products.allProducts, defaultProducts),
parseLine: createParseLine, parseLine: createParseLine,
parseLocation, parseLocation,
parseJourney: createParseJourney,
formatProducts, formatProducts,