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