This repository has been archived by the owner on Mar 31, 2021. It is now read-only.
forked from public-transport/hafas-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest-exe-example.js
61 lines (53 loc) · 1.53 KB
/
rest-exe-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
const createClient = require('./rest-exe')
const TOKEN = process.env.TOKEN
if (!TOKEN) throw new Error('missing TOKEN env var')
const profile = {
endpoint: 'https://dbrest-rt.hafas.de/openapi/1.23/'
}
const {
locations, nearby,
departures, arrivals,
journeys, trip, tripAlternatives
// tripHistory,
// radar,
// remarks, dataInfo
} = createClient(profile, TOKEN, 'hafas-client example')
const berlinOstkreuz = '8011162'
const berlinSchönefeld = '8010109'
const berlinWestkreuz = '8089047'
const berlinMesseSüd = '8089328'
const berlinYorckstrS1 = '8089051'
const somewhereInBerlin = {type: 'location', address: 'foo', latitude: 52.51072, longitude: 13.37793}
// journeys(berlinOstkreuz, '8000261', {
// results: 3,
// stopovers: true,
// remarks: true
// })
// .then(journeys => journeys.flatMap(j => [...j.legs, '---']))
// .then(([journey]) => journey.legs.map(l => l.tripId).find(tripId => !!tripId))
// .then(trip)
// .then(tripHistory)
// tripAlternatives()
locations('leopoldplatz ber')
// nearby({type: 'location', latitude: 52.4751309, longitude: 13.3656537})
// departures(berlinYorckstrS1, {
// remarks: true
// })
// .then(deps => deps.map(d => [d.line && d.line.name, d.stop && d.stop.name]))
// arrivals(berlinYorckstrS1, {
// remarks: true
// })
// radar({
// north: 52.52411,
// west: 13.41002,
// south: 52.51942,
// east: 13.41709
// })
// remarks()
// dataInfo()
.then(data => console.log(require('util').inspect(data, {depth: null, colors: true})))
.catch((err) => {
console.error(err)
process.exit(1)
})