db-vendo-client/p/insa/index.js

83 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-02-26 22:14:11 +01:00
'use strict'
2018-03-13 02:29:09 +01:00
const _createParseLine = require('../../parse/line')
2018-02-26 22:14:11 +01:00
const products = require('./products')
const createParseBitmask = require('../../parse/products-bitmask')
const createFormatBitmask = require('../../format/products-bitmask')
const defaultProducts = {
nationalExp: true,
national: true,
regional: true,
suburban: true,
bus: true,
tram: true,
tourismTrain: true,
}
const transformReqBody = (body) => {
body.client = {
type: 'IPH',
id: 'NASA',
v: '4000200',
name: 'nasaPROD',
os: 'iPhone OS 11.2.5'
}
body.ver = '1.11'
body.auth = {aid: "nasa-apps"}
body.lang = 'en' // todo: `de`?
return body
}
2018-03-13 02:29:09 +01:00
const createParseLine = (profile, operators) => {
const parseLine = _createParseLine(profile, operators)
2018-02-26 22:14:11 +01:00
2018-03-13 02:29:09 +01:00
const parseLineWithMode = (l) => {
const res = parseLine(l)
res.mode = res.product = null
if ('class' in res) {
const data = products.bitmasks[parseInt(res.class)]
if (data) {
res.mode = data.mode
res.product = data.product
}
}
return res
}
return parseLineWithMode
}
2018-02-26 22:14:11 +01:00
const formatProducts = (products) => {
products = Object.assign(Object.create(null), defaultProducts, products)
return {
type: 'PROD',
mode: 'INC',
value: formatBitmask(products) + ''
}
}
const formatBitmask = createFormatBitmask(products)
const insaProfile = {
locale: 'de-DE',
timezone: 'Europe/Berlin',
endpoint: 'http://reiseauskunft.insa.de/bin/mgate.exe',
transformReqBody,
products: products.allProducts,
parseProducts: createParseBitmask(products.allProducts, defaultProducts),
2018-03-13 02:29:09 +01:00
formatProducts,
2018-03-13 21:04:42 +01:00
parseLine: createParseLine,
2018-02-26 22:14:11 +01:00
2018-03-13 21:12:46 +01:00
journeyLeg: true,
2018-03-13 21:06:27 +01:00
radar: true
2018-02-26 22:14:11 +01:00
}
module.exports = insaProfile;