Skip to content

Commit 0b8571e

Browse files
committed
rest.exe client: WIP
1 parent d743bd0 commit 0b8571e

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

format-rest/date.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
3+
const {DateTime, IANAZone} = require('luxon')
4+
5+
const timezones = new WeakMap()
6+
7+
const formatDate = (profile, when) => {
8+
let timezone
9+
if (timezones.has(profile)) timezone = timezones.get(profile)
10+
else {
11+
timezone = new IANAZone(profile.timezone)
12+
timezones.set(profile, timezone)
13+
}
14+
15+
return DateTime.fromMillis(+when, {
16+
locale: profile.locale,
17+
zone: timezone
18+
}).toFormat('yyyy-MM-dd')
19+
}
20+
21+
module.exports = formatDate

rest-exe.js

+51-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const parseStopover = require('./parse-rest/stopover')
1717
const parseLocation = require('./parse-rest/location')
1818
const parseArrivalOrDeparture = require('./parse-rest/arrival-or-departure')
1919
const parseTrip = require('./parse-rest/trip')
20+
const formatDate = require('./format-rest/date')
2021
const defaultProfile = require('./lib/default-profile')
2122
const _profile = require('./p/db')
2223

@@ -97,7 +98,8 @@ const profile = {
9798
parseJourney,
9899
parseJourneyLeg,
99100
parseStopover,
100-
parseLocation
101+
parseLocation,
102+
formatDate
101103
}
102104

103105
const opt = {
@@ -222,15 +224,63 @@ const trip = async (id) => {
222224
return parseTrip(profile, opt, {})(res)
223225
}
224226

227+
// todo: fails with 404
228+
// const tripHistory = async (tripId) => {
229+
// const res = await request('rtarchive', {
230+
// id: tripId,
231+
// date: profile.formatDate(profile, opt.when || Date.now())
232+
// })
233+
// return res
234+
// }
235+
236+
// todo: fails with 404
237+
// const radar = async (bbox) => {
238+
// const res = await request('journeyPos', {
239+
// llLat: bbox.south,
240+
// llLon: bbox.west,
241+
// urLat: bbox.north,
242+
// urLon: bbox.east,
243+
// // todo: operators, products, attributes, lines, jid, infotexts
244+
// // todo: maxJny, time
245+
// date: profile.formatDate(profile, opt.when || Date.now())
246+
// })
247+
// return res
248+
// }
249+
250+
// todo: fails with 404
251+
// const remarks = async () => {
252+
// const res = await request('himSearch', {
253+
// // todo: dateB, dateE, timeB, timeE, himIds, operators, categories
254+
// // todo: channels, companies, metas, himcategory, poly, searchmode
255+
// // todo: minprio, maxprio
256+
// })
257+
// return res
258+
// }
259+
260+
// todo: fails with 404
261+
// const dataInfo = async () => {
262+
// const res = await request('datainfo')
263+
// return res
264+
// }
265+
225266
// journeys()
226267
// .then(([journey]) => journey.legs.map(l => l.tripId).find(tripId => !!tripId))
227268
// .then(trip)
269+
// .then(tripHistory)
228270

229271
// locations('leopoldplatz berlin')
230272
// nearby({type: 'location', latitude: 52.4751309, longitude: 13.3656537})
231273
// tripAlternatives()
232274
// departures()
233275
// arrivals()
276+
// radar({
277+
// north: 52.52411,
278+
// west: 13.41002,
279+
// south: 52.51942,
280+
// east: 13.41709
281+
// })
282+
// remarks()
283+
// dataInfo()
234284

235285
.then(data => console.error(require('util').inspect(data, {depth: null, colors: true})))
236286
.catch((err) => {

0 commit comments

Comments
 (0)