adapt docs to fcc53b5 📝

[ci skip]
This commit is contained in:
Jannis R 2019-01-16 21:40:45 +08:00
parent fcc53b5d2a
commit b2b2d11dfe
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
8 changed files with 131 additions and 115 deletions

View file

@ -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)
```

View file

@ -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) => {

View file

@ -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})
// })

View file

@ -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})
// })

View file

@ -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})
// })

View file

@ -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
// })

View file

@ -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) => {

186
readme.md
View file

@ -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: /* … */
}
```