From b2b2d11dfe54309b59acd522d6045f5d112825c6 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Wed, 16 Jan 2019 21:40:45 +0800 Subject: [PATCH] adapt docs to fcc53b5 :memo: [ci skip] --- docs/journeys.md | 24 ++--- p/bvg/example.js | 6 +- p/cmta/example.js | 6 +- p/insa/example.js | 6 +- p/saarfahrplan/example.js | 6 +- p/sbahn-muenchen/example.js | 6 +- p/vbb/example.js | 6 +- readme.md | 186 ++++++++++++++++++------------------ 8 files changed, 131 insertions(+), 115 deletions(-) diff --git a/docs/journeys.md b/docs/journeys.md index 1a5662e2..7d1f81a1 100644 --- a/docs/journeys.md +++ b/docs/journeys.md @@ -95,11 +95,11 @@ client.journeys('900000003201', '900000100008', { .catch(console.error) ``` -The response may look like this: +The `Promise` returned by `journeys()` will resolve with an object with the `journeys` & `earlierRef`/`laterRef` fields. It might look like this: ```js -[ - { +{ + journeys: [ { legs: [ { tripId: '1|32615|6|86|10072018', origin: { @@ -226,10 +226,10 @@ The response may look like this: public: true, distance: 558 } ] - }, + } ], earlierRef: '…', // use with the `earlierThan` option laterRef: '…' // use with the `laterThan` option -] +} ``` Some [profiles](../p) are able to parse the ticket information, if returned by the API. For example, if you pass `tickets: true` with the [VBB profile](../p/vbb), each `journey` will have a tickets array that looks like this: @@ -271,25 +271,25 @@ Some [profiles](../p) are able to parse the ticket information, if returned by t If a journey leg has been cancelled, a `cancelled: true` will be added. Also, `departure`/`departureDelay`/`departurePlatform` and `arrival`/`arrivalDelay`/`arrivalPlatform` will be `null`. -To get more journeys earlier/later than the current set of results, pass `journeys.earlierRef`/`journeys.laterRef` into `opt.earlierThan`/`opt.laterThan`. For example, query *later* journeys as follows: +To get more journeys earlier/later than the current set of results, pass `earlierRef`/`laterRef` into `opt.earlierThan`/`opt.laterThan`. For example, query *later* journeys as follows: ```js const hbf = '900000003201' const heinrichHeineStr = '900000100008' client.journeys(hbf, heinrichHeineStr) -.then((journeys) => { - const lastJourney = journeys[journeys.length - 1] +.then((res) => { + const lastJourney = res.journeys[res.journeys.length - 1] console.log('departure of last journey', lastJourney.legs[0].departure) // get later journeys return client.journeys(hbf, heinrichHeineStr, { - laterThan: journeys.laterRef + laterThan: res.laterRef }) }) -.then((laterJourneys) => { - const firstJourney = laterJourneys[laterJourneys.length - 1] - console.log('departure of first (later) journey', firstJourney.legs[0].departure) +.then((laterRes) => { + const firstLaterJourney = laterRes.journeys[laterRes.journeys.length - 1] + console.log('departure of first (later) journey', firstLaterJourney.legs[0].departure) }) .catch(console.error) ``` diff --git a/p/bvg/example.js b/p/bvg/example.js index bc54e6b6..43096c10 100644 --- a/p/bvg/example.js +++ b/p/bvg/example.js @@ -32,12 +32,14 @@ client.journeys('900000003201', '900000024101', {results: 1, polylines: true}) // maxDuration: 10 // }) -// .then(([journey]) => { +// .then(({journeys}) => { +// const [journey] = journeys // const leg = journey.legs[0] // return client.trip(leg.tripId, leg.line.name, {polyline: true}) // }) -// .then(([journey]) => { +// .then(({journeys}) => { +// const [journey] = journeys // return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) // }) .then((data) => { diff --git a/p/cmta/example.js b/p/cmta/example.js index b88288ae..0906dc09 100644 --- a/p/cmta/example.js +++ b/p/cmta/example.js @@ -32,11 +32,13 @@ client.journeys('000002370', '000005919', {results: 1, polylines: true}) // maxDuration: 15 // }) -// .then(([journey]) => { +// .then(({journeys}) => { +// const [journey] = journeys // const leg = journey.legs[0] // return client.trip(leg.tripId, leg.line.name, {polyline: true}) // }) -// .then(([journey]) => { +// .then(({journeys}) => { +// const [journey] = journeys // return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) // }) diff --git a/p/insa/example.js b/p/insa/example.js index 4ee13095..7f18b769 100644 --- a/p/insa/example.js +++ b/p/insa/example.js @@ -24,12 +24,14 @@ client.journeys('008010226', '008013456', {results: 1}) // east: 11.651451 // }, {results: 10}) -// .then(([journey]) => { +// .then(({journeys}) => { +// const [journey] = journeys // const leg = journey.legs[0] // return client.trip(leg.tripId, leg.line.name) // }) -// .then(([journey]) => { +// .then(({journeys}) => { +// const [journey] = journeys // return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) // }) diff --git a/p/saarfahrplan/example.js b/p/saarfahrplan/example.js index 413dfa51..c25bb088 100644 --- a/p/saarfahrplan/example.js +++ b/p/saarfahrplan/example.js @@ -6,11 +6,13 @@ const saarfahrplanProfile = require('.') const client = createClient(saarfahrplanProfile, 'hafas-client-example') client.journeys('15541', '10609', {results: 1}) -// .then(([journey]) => { +// .then(({journeys}) => { +// const [journey] = journeys // const leg = journey.legs[0] // return client.trip(leg.id, leg.line.name, {polyline: true}) // }) -// .then(([journey]) => { +// .then(({journeys}) => { +// const [journey] = journeys // return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) // }) diff --git a/p/sbahn-muenchen/example.js b/p/sbahn-muenchen/example.js index fd0155f4..a70faac8 100644 --- a/p/sbahn-muenchen/example.js +++ b/p/sbahn-muenchen/example.js @@ -32,12 +32,14 @@ client.departures('8004154', {duration: 5}) // maxDuration: 20 // }) -// .then(([journey]) => { +// .then(({journeys}) => { +// const [journey] = journeys // const leg = journey.legs.find(leg => leg.line) // return client.trip(leg.tripId, leg.line.name, {polyline: true}) // }) -// .then(([journey]) => { +// .then(({journeys}) => { +// const [journey] = journeys // return client.refreshJourney(journey.refreshToken, { // stopovers: true, remarks: true // }) diff --git a/p/vbb/example.js b/p/vbb/example.js index bc54e6b6..43096c10 100644 --- a/p/vbb/example.js +++ b/p/vbb/example.js @@ -32,12 +32,14 @@ client.journeys('900000003201', '900000024101', {results: 1, polylines: true}) // maxDuration: 10 // }) -// .then(([journey]) => { +// .then(({journeys}) => { +// const [journey] = journeys // const leg = journey.legs[0] // return client.trip(leg.tripId, leg.line.name, {polyline: true}) // }) -// .then(([journey]) => { +// .then(({journeys}) => { +// const [journey] = journeys // return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) // }) .then((data) => { diff --git a/readme.md b/readme.md index e5f79da2..5cdf43b9 100644 --- a/readme.md +++ b/readme.md @@ -60,82 +60,103 @@ client.journeys('8011167', '8000261', {results: 1}) .catch(console.error) ``` -The returned [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/promise) will resolve with an array of one [*FPTF* `journey`](https://github.com/public-transport/friendly-public-transport-format/blob/1.2.0/spec/readme.md#journey). +The returned [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/promise) will resolve with an object with an array `journeys` that contains one [*FPTF* `journey`](https://github.com/public-transport/friendly-public-transport-format/blob/1.2.0/spec/readme.md#journey). ```js -[ { - legs: [ { - id: '1|100067|48|81|17122017', +{ + journeys: [ { + legs: [ { + id: '1|100067|48|81|17122017', + origin: { + type: 'station', + id: '8089100', + name: 'Berlin Jungfernheide (S)', + location: { + type: 'location', + latitude: 52.530291, + longitude: 13.299451 + }, + products: { /* … */ } + }, + departure: '2017-12-17T17:05:00.000+01:00', + departurePlatform: '5', + destination: { + type: 'station', + id: '8089118', + name: 'Berlin Beusselstraße', + location: { /* … */ }, + products: { /* … */ } + }, + arrival: '2017-12-17T17:08:00.000+01:00', + arrivalPlatform: '1', + line: { + type: 'line', + id: '41172', + name: 'S 41', + public: true, + mode: 'train', + product: 'suburban', + operator: { + type: 'operator', + id: 's-bahn-berlin-gmbh', + name: 'S-Bahn Berlin GmbH' + } + }, + direction: 'Ringbahn ->' + }, /* … */ { + origin: { + type: 'station', + id: '730749', + name: 'Berlin Hauptbahnhof (S+U), Berlin', + location: { + type: 'location', + latitude: 52.526461, + longitude: 13.369378 + }, + products: { /* … */ } + }, + departure: '2017-12-17T17:25:00.000+01:00', + destination: { + type: 'station', + id: '8098160', + name: 'Berlin Hbf (tief)', + location: { /* … */ }, + products: { /* … */ } + }, + arrival: '2017-12-17T17:33:00.000+01:00', + mode: 'walking', + public: true + }, { + id: '1|70906|0|81|17122017', + origin: { + type: 'station', + id: '8098160', + name: 'Berlin Hbf (tief)', + location: { /* … */ }, + products: { /* … */ } + }, + departure: '2017-12-17T17:37:00.000+01:00', + departurePlatform: '1', + destination: { + type: 'station', + id: '8000261', + name: 'München Hbf', + location: { /* … */ }, + products: { /* … */ } + }, + arrival: '2017-12-17T22:45:00.000+01:00', + arrivalPlatform: '13', + line: { /* … */ }, + direction: 'München Hbf' + } ], origin: { type: 'station', id: '8089100', name: 'Berlin Jungfernheide (S)', - location: { - type: 'location', - latitude: 52.530291, - longitude: 13.299451 - }, + location: { /* … */ }, products: { /* … */ } }, departure: '2017-12-17T17:05:00.000+01:00', - departurePlatform: '5', - destination: { - type: 'station', - id: '8089118', - name: 'Berlin Beusselstraße', - location: { /* … */ }, - products: { /* … */ } - }, - arrival: '2017-12-17T17:08:00.000+01:00', - arrivalPlatform: '1', - line: { - type: 'line', - id: '41172', - name: 'S 41', - public: true, - mode: 'train', - product: 'suburban', - operator: { - type: 'operator', - id: 's-bahn-berlin-gmbh', - name: 'S-Bahn Berlin GmbH' - } - }, - direction: 'Ringbahn ->' - }, /* … */ { - origin: { - type: 'station', - id: '730749', - name: 'Berlin Hauptbahnhof (S+U), Berlin', - location: { - type: 'location', - latitude: 52.526461, - longitude: 13.369378 - }, - products: { /* … */ } - }, - departure: '2017-12-17T17:25:00.000+01:00', - destination: { - type: 'station', - id: '8098160', - name: 'Berlin Hbf (tief)', - location: { /* … */ }, - products: { /* … */ } - }, - arrival: '2017-12-17T17:33:00.000+01:00', - mode: 'walking', - public: true - }, { - id: '1|70906|0|81|17122017', - origin: { - type: 'station', - id: '8098160', - name: 'Berlin Hbf (tief)', - location: { /* … */ }, - products: { /* … */ } - }, - departure: '2017-12-17T17:37:00.000+01:00', - departurePlatform: '1', destination: { type: 'station', id: '8000261', @@ -144,31 +165,14 @@ The returned [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript products: { /* … */ } }, arrival: '2017-12-17T22:45:00.000+01:00', - arrivalPlatform: '13', - line: { /* … */ }, - direction: 'München Hbf' + price: { + amount: null, + hint: 'No pricing information available.' + } } ], - origin: { - type: 'station', - id: '8089100', - name: 'Berlin Jungfernheide (S)', - location: { /* … */ }, - products: { /* … */ } - }, - departure: '2017-12-17T17:05:00.000+01:00', - destination: { - type: 'station', - id: '8000261', - name: 'München Hbf', - location: { /* … */ }, - products: { /* … */ } - }, - arrival: '2017-12-17T22:45:00.000+01:00', - price: { - amount: null, - hint: 'No pricing information available.' - } -} ] + earlierRef: /* … */, + laterRef: /* … */ +} ```