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,
|
|
|
|
|
2018-03-13 03:23:03 +01:00
|
|
|
parseProducts: createParseBitmask(products.allProducts, defaultProducts),
|
2018-03-13 02:29:09 +01:00
|
|
|
formatProducts,
|
|
|
|
|
|
|
|
parseLine: createParseLine
|
2018-02-26 22:14:11 +01:00
|
|
|
|
|
|
|
// todo: journeyLeg?
|
|
|
|
// todo: radar?
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = insaProfile;
|