mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-04-20 23:23:56 +03:00
add dbris, moreStops param
This commit is contained in:
parent
b887c674d4
commit
b20cf1060a
7 changed files with 139 additions and 74 deletions
2
api.js
2
api.js
|
@ -2,6 +2,7 @@ import {createClient} from './index.js';
|
||||||
import {profile as dbProfile} from './p/db/index.js';
|
import {profile as dbProfile} from './p/db/index.js';
|
||||||
import {profile as dbnavProfile} from './p/dbnav/index.js';
|
import {profile as dbnavProfile} from './p/dbnav/index.js';
|
||||||
import {profile as dbwebProfile} from './p/dbweb/index.js';
|
import {profile as dbwebProfile} from './p/dbweb/index.js';
|
||||||
|
import {profile as dbrisProfile} from './p/dbris/index.js';
|
||||||
import {mapRouteParsers} from './lib/api-parsers.js';
|
import {mapRouteParsers} from './lib/api-parsers.js';
|
||||||
import {createHafasRestApi as createApi} from 'hafas-rest-api';
|
import {createHafasRestApi as createApi} from 'hafas-rest-api';
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ const profiles = {
|
||||||
db: dbProfile,
|
db: dbProfile,
|
||||||
dbnav: dbnavProfile,
|
dbnav: dbnavProfile,
|
||||||
dbweb: dbwebProfile,
|
dbweb: dbwebProfile,
|
||||||
|
dbris: dbrisProfile,
|
||||||
};
|
};
|
||||||
|
|
||||||
const start = async () => {
|
const start = async () => {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
const formatStationBoardReq = (ctx, station, type) => {
|
const formatStationBoardReq = (ctx, station, type) => {
|
||||||
const {profile, opt} = ctx;
|
const {profile, opt} = ctx;
|
||||||
|
|
||||||
|
if (opt.moreStops) {
|
||||||
|
station += ',' + opt.moreStops.join(',');
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
endpoint: profile.boardEndpoint,
|
endpoint: profile.boardEndpoint,
|
||||||
path: (type == 'departures' ? 'departure' : 'arrival') + '/' + station,
|
path: (type == 'departures' ? 'departure' : 'arrival') + '/' + station,
|
||||||
|
@ -15,35 +19,6 @@ const formatStationBoardReq = (ctx, station, type) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
TODO separate RIS::Boards profile?
|
|
||||||
const formatRisStationBoardReq = (ctx, station, type) => {
|
|
||||||
const {profile, opt} = ctx;
|
|
||||||
|
|
||||||
return {
|
|
||||||
endpoint: profile.boardEndpoint,
|
|
||||||
path: type + '/' + station,
|
|
||||||
query: {
|
|
||||||
// TODO direction
|
|
||||||
filterTransports: profile.formatProductsFilter(ctx, opt.products || {}, 'ris'),
|
|
||||||
timeStart: profile.formatTime(profile, opt.when, true),
|
|
||||||
timeEnd: profile.formatTime(profile, opt.when.getTime() + opt.duration * 60 * 1000, true),
|
|
||||||
maxViaStops: opt.stopovers ? undefined : 0,
|
|
||||||
includeStationGroup: opt.includeRelatedStations,
|
|
||||||
maxTransportsPerType: opt.results === Infinity ? undefined : opt.results,
|
|
||||||
includeMessagesDisruptions: opt.remarks,
|
|
||||||
sortBy: 'TIME_SCHEDULE',
|
|
||||||
},
|
|
||||||
method: 'get',
|
|
||||||
headers: {
|
|
||||||
'Db-Client-Id': process.env.DB_CLIENT_ID,
|
|
||||||
'Db-Api-Key': process.env.DB_API_KEY,
|
|
||||||
'Accept': 'application/vnd.de.db.ris+json',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
formatStationBoardReq,
|
formatStationBoardReq,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {data as cards} from '../format/loyalty-cards.js';
|
import {data as cards} from '../format/loyalty-cards.js';
|
||||||
import {parseBoolean, parseInteger} from 'hafas-rest-api/lib/parse.js';
|
import {parseBoolean, parseInteger, parseArrayOfStrings} from 'hafas-rest-api/lib/parse.js';
|
||||||
|
|
||||||
const typesByName = new Map([
|
const typesByName = new Map([
|
||||||
['bahncard-1st-25', {type: cards.BAHNCARD, discount: 25, class: 1}],
|
['bahncard-1st-25', {type: cards.BAHNCARD, discount: 25, class: 1}],
|
||||||
|
@ -42,43 +42,54 @@ const parseArrayOr = (parseEntry) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapRouteParsers = (route, parsers) => {
|
const mapRouteParsers = (route, parsers) => {
|
||||||
if (route !== 'journeys' && route !== 'refresh-journey') {
|
if (route.includes('journey')) {
|
||||||
return parsers;
|
return {
|
||||||
|
...parsers,
|
||||||
|
firstClass: {
|
||||||
|
description: 'Search for first-class options?',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
parse: parseBoolean,
|
||||||
|
},
|
||||||
|
loyaltyCard: {
|
||||||
|
description: 'Type of loyalty card in use.',
|
||||||
|
type: 'string',
|
||||||
|
enum: types,
|
||||||
|
defaultStr: '*none*',
|
||||||
|
parse: parseArrayOr(parseLoyaltyCard),
|
||||||
|
},
|
||||||
|
age: {
|
||||||
|
description: 'Age of traveller',
|
||||||
|
type: 'integer',
|
||||||
|
defaultStr: '*adult*',
|
||||||
|
parse: parseArrayOr(parseInteger),
|
||||||
|
},
|
||||||
|
notOnlyFastRoutes: {
|
||||||
|
description: 'If true, also show routes that are mathematically non-optimal',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
parse: parseBoolean,
|
||||||
|
},
|
||||||
|
bestprice: {
|
||||||
|
description: 'Search for lowest prices across the entire day',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
parse: parseBoolean,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return {
|
if (route.includes('departures') || route.includes('arrivals')) {
|
||||||
...parsers,
|
return {
|
||||||
firstClass: {
|
...parsers,
|
||||||
description: 'Search for first-class options?',
|
moreStops: {
|
||||||
type: 'boolean',
|
description: 'Also include departures/arrivals for up to nine comma-separated station evaNumbers',
|
||||||
default: false,
|
type: 'string',
|
||||||
parse: parseBoolean,
|
default: '',
|
||||||
},
|
parse: parseArrayOfStrings,
|
||||||
loyaltyCard: {
|
},
|
||||||
description: 'Type of loyalty card in use.',
|
};
|
||||||
type: 'string',
|
}
|
||||||
enum: types,
|
return parsers;
|
||||||
defaultStr: '*none*',
|
|
||||||
parse: parseArrayOr(parseLoyaltyCard),
|
|
||||||
},
|
|
||||||
age: {
|
|
||||||
description: 'Age of traveller',
|
|
||||||
type: 'integer',
|
|
||||||
defaultStr: '*adult*',
|
|
||||||
parse: parseArrayOr(parseInteger),
|
|
||||||
},
|
|
||||||
notOnlyFastRoutes: {
|
|
||||||
description: 'If true, also show routes that are mathematically non-optimal',
|
|
||||||
type: 'boolean',
|
|
||||||
default: false,
|
|
||||||
parse: parseBoolean,
|
|
||||||
},
|
|
||||||
bestprice: {
|
|
||||||
description: 'Search for lowest prices across the entire day',
|
|
||||||
type: 'boolean',
|
|
||||||
default: false,
|
|
||||||
parse: parseBoolean,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
4
p/dbris/base.json
Normal file
4
p/dbris/base.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"boardEndpoint": "https://apis.deutschebahn.com/db/apis/ris-boards/v1/public/",
|
||||||
|
"defaultLanguage": "en"
|
||||||
|
}
|
32
p/dbris/index.js
Normal file
32
p/dbris/index.js
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import baseProfile from './base.json' with { type: 'json' };
|
||||||
|
import {products} from '../../lib/products.js';
|
||||||
|
import {formatStationBoardReq} from './station-board-req.js';
|
||||||
|
|
||||||
|
const profile = {
|
||||||
|
...baseProfile,
|
||||||
|
locale: 'de-DE',
|
||||||
|
timezone: 'Europe/Berlin',
|
||||||
|
|
||||||
|
products,
|
||||||
|
|
||||||
|
|
||||||
|
formatStationBoardReq,
|
||||||
|
|
||||||
|
journeysOutFrwd: true,
|
||||||
|
departuresGetPasslist: true,
|
||||||
|
departuresStbFltrEquiv: true,
|
||||||
|
trip: false,
|
||||||
|
radar: false,
|
||||||
|
refreshJourney: false,
|
||||||
|
journeysFromTrip: false,
|
||||||
|
refreshJourneyUseOutReconL: false,
|
||||||
|
tripsByName: false,
|
||||||
|
remarks: false,
|
||||||
|
remarksGetPolyline: false,
|
||||||
|
reachableFrom: false,
|
||||||
|
lines: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
profile,
|
||||||
|
};
|
34
p/dbris/station-board-req.js
Normal file
34
p/dbris/station-board-req.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
const formatStationBoardReq = (ctx, station, type) => {
|
||||||
|
const {profile, opt} = ctx;
|
||||||
|
|
||||||
|
const query = {
|
||||||
|
filterTransports: profile.formatProductsFilter(ctx, opt.products || {}, 'ris_alt'),
|
||||||
|
timeStart: profile.formatTime(profile, opt.when, true),
|
||||||
|
timeEnd: profile.formatTime(profile, opt.when.getTime() + opt.duration * 60 * 1000, true),
|
||||||
|
includeStationGroup: opt.includeRelatedStations,
|
||||||
|
maxTransportsPerType: opt.results === Infinity ? undefined : opt.results,
|
||||||
|
includeMessagesDisruptions: opt.remarks,
|
||||||
|
sortBy: 'TIME_SCHEDULE',
|
||||||
|
};
|
||||||
|
if (!opt.stopovers) {
|
||||||
|
query.maxViaStops = 0;
|
||||||
|
}
|
||||||
|
if (opt.moreStops) {
|
||||||
|
station += ',' + opt.moreStops.join(',');
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
endpoint: profile.boardEndpoint,
|
||||||
|
path: type + '/' + station,
|
||||||
|
query: query,
|
||||||
|
method: 'get',
|
||||||
|
headers: {
|
||||||
|
'Db-Client-Id': process.env.DB_CLIENT_ID,
|
||||||
|
'Db-Api-Key': process.env.DB_API_KEY,
|
||||||
|
'Accept': 'application/vnd.de.db.ris+json',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
formatStationBoardReq,
|
||||||
|
};
|
|
@ -40,14 +40,21 @@ const createParseArrOrDep = (prefix) => {
|
||||||
res.remarks = profile.parseRemarks(ctx, d);
|
res.remarks = profile.parseRemarks(ctx, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((opt.stopovers || opt.direction) && Array.isArray(d.ueber)) {
|
if (opt.stopovers || opt.direction) {
|
||||||
const stopovers = d.ueber
|
let stopovers = undefined;
|
||||||
.map(viaName => profile.parseStopover(ctx, {name: viaName}, null));
|
if (Array.isArray(d.ueber)) {
|
||||||
|
stopovers = d.ueber
|
||||||
if (prefix === ARRIVAL) {
|
.map(viaName => profile.parseStopover(ctx, {name: viaName}, null));
|
||||||
res.previousStopovers = stopovers;
|
} else if (Array.isArray(d.transport?.via)) {
|
||||||
} else if (prefix === DEPARTURE) {
|
stopovers = (d.transport?.via)
|
||||||
res.nextStopovers = stopovers;
|
.map(via => profile.parseStopover(ctx, via, null));
|
||||||
|
}
|
||||||
|
if (stopovers) {
|
||||||
|
if (prefix === ARRIVAL) {
|
||||||
|
res.previousStopovers = stopovers;
|
||||||
|
} else if (prefix === DEPARTURE) {
|
||||||
|
res.nextStopovers = stopovers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue