mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
docs: .then/.catch -> await 📝
[ci skip]
This commit is contained in:
parent
d5969bc0c4
commit
90308411fc
15 changed files with 43 additions and 71 deletions
|
@ -1,3 +1,3 @@
|
||||||
# `arrivals(station, [opt])`
|
# `arrivals(station, [opt])`
|
||||||
|
|
||||||
Just like [`departures(station, [opt])`](departures.md), except that it gives arrival times instead of departure times.
|
Just like [`departures(station, [opt])`](departures.md), except that it resolves with arrival times instead of departure times.
|
||||||
|
|
|
@ -48,7 +48,7 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
const client = createClient(vbbProfile, 'my-awesome-program')
|
const client = createClient(vbbProfile, 'my-awesome-program')
|
||||||
|
|
||||||
// will query with these products: suburban, subway, bus, express, regional
|
// will query with these products: suburban, subway, bus, express, regional
|
||||||
client.departures('900000024101', {products: {tram: false, ferry: false}})
|
await client.departures('900000024101', {products: {tram: false, ferry: false}})
|
||||||
```
|
```
|
||||||
|
|
||||||
## Response
|
## Response
|
||||||
|
@ -66,12 +66,10 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
const client = createClient(vbbProfile, 'my-awesome-program')
|
const client = createClient(vbbProfile, 'my-awesome-program')
|
||||||
|
|
||||||
// S Charlottenburg
|
// S Charlottenburg
|
||||||
client.departures('900000024101', {duration: 3})
|
await client.departures('900000024101', {duration: 3})
|
||||||
.then(console.log)
|
|
||||||
.catch(console.error)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The response may look like this:
|
The result may look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
[ {
|
[ {
|
||||||
|
|
|
@ -91,15 +91,13 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
const client = createClient(vbbProfile, 'my-awesome-program')
|
const client = createClient(vbbProfile, 'my-awesome-program')
|
||||||
|
|
||||||
// Hauptbahnhof to Heinrich-Heine-Str.
|
// Hauptbahnhof to Heinrich-Heine-Str.
|
||||||
client.journeys('900000003201', '900000100008', {
|
await client.journeys('900000003201', '900000100008', {
|
||||||
results: 1,
|
results: 1,
|
||||||
stopovers: true
|
stopovers: true
|
||||||
})
|
})
|
||||||
.then(console.log)
|
|
||||||
.catch(console.error)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The `Promise` returned by `journeys()` will resolve with an object with the `journeys` & `earlierRef`/`laterRef` fields. It might look like this:
|
`journeys()` will resolve with an object with the `journeys` & `earlierRef`/`laterRef` fields. It might look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
|
@ -317,21 +315,16 @@ To get more journeys earlier/later than the current set of results, pass `earlie
|
||||||
const hbf = '900000003201'
|
const hbf = '900000003201'
|
||||||
const heinrichHeineStr = '900000100008'
|
const heinrichHeineStr = '900000100008'
|
||||||
|
|
||||||
client.journeys(hbf, heinrichHeineStr)
|
const res1 = await client.journeys(hbf, heinrichHeineStr)
|
||||||
.then((res) => {
|
const lastJourney = res1.journeys[res1.journeys.length - 1]
|
||||||
const lastJourney = res.journeys[res.journeys.length - 1]
|
|
||||||
console.log('departure of last journey', lastJourney.legs[0].departure)
|
console.log('departure of last journey', lastJourney.legs[0].departure)
|
||||||
|
|
||||||
// get later journeys
|
// get later journeys
|
||||||
return client.journeys(hbf, heinrichHeineStr, {
|
const res2 = await client.journeys(hbf, heinrichHeineStr, {
|
||||||
laterThan: res.laterRef
|
laterThan: res1.laterRef
|
||||||
})
|
})
|
||||||
})
|
const firstLaterJourney = res2.journeys[res2.journeys.length - 1]
|
||||||
.then((laterRes) => {
|
|
||||||
const firstLaterJourney = laterRes.journeys[laterRes.journeys.length - 1]
|
|
||||||
console.log('departure of first (later) journey', firstLaterJourney.legs[0].departure)
|
console.log('departure of first (later) journey', firstLaterJourney.legs[0].departure)
|
||||||
})
|
|
||||||
.catch(console.error)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -12,7 +12,7 @@ const svvProfile = require('hafas-client/p/svv')
|
||||||
|
|
||||||
const client = createClient(svvProfile, 'my-awesome-program')
|
const client = createClient(svvProfile, 'my-awesome-program')
|
||||||
|
|
||||||
console.log(await client.lines('S1'))
|
await client.lines('S1')
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
|
@ -28,12 +28,10 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
|
|
||||||
const client = createClient(vbbProfile, 'my-awesome-program')
|
const client = createClient(vbbProfile, 'my-awesome-program')
|
||||||
|
|
||||||
client.locations('Alexanderplatz', {results: 3})
|
await client.locations('Alexanderplatz', {results: 3})
|
||||||
.then(console.log)
|
|
||||||
.catch(console.error)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The response may look like this:
|
The result may look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
[ {
|
[ {
|
||||||
|
|
|
@ -29,16 +29,14 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
|
|
||||||
const client = createClient(vbbProfile, 'my-awesome-program')
|
const client = createClient(vbbProfile, 'my-awesome-program')
|
||||||
|
|
||||||
client.nearby({
|
await client.nearby({
|
||||||
type: 'location',
|
type: 'location',
|
||||||
latitude: 52.5137344,
|
latitude: 52.5137344,
|
||||||
longitude: 13.4744798
|
longitude: 13.4744798
|
||||||
}, {distance: 400})
|
}, {distance: 400})
|
||||||
.then(console.log)
|
|
||||||
.catch(console.error)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The response may look like this:
|
The result may look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
[ {
|
[ {
|
||||||
|
|
|
@ -30,17 +30,15 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
|
|
||||||
const client = createClient(vbbProfile, 'my-awesome-program')
|
const client = createClient(vbbProfile, 'my-awesome-program')
|
||||||
|
|
||||||
client.radar({
|
await client.radar({
|
||||||
north: 52.52411,
|
north: 52.52411,
|
||||||
west: 13.41002,
|
west: 13.41002,
|
||||||
south: 52.51942,
|
south: 52.51942,
|
||||||
east: 13.41709
|
east: 13.41709
|
||||||
}, {results: 5})
|
}, {results: 5})
|
||||||
.then(console.log)
|
|
||||||
.catch(console.error)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The response may look like this:
|
The result may look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
[ {
|
[ {
|
||||||
|
|
|
@ -36,19 +36,17 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
|
|
||||||
const client = createClient(vbbProfile, 'my-awesome-program')
|
const client = createClient(vbbProfile, 'my-awesome-program')
|
||||||
|
|
||||||
client.reachableFrom({
|
console.log(await client.reachableFrom({
|
||||||
type: 'location',
|
type: 'location',
|
||||||
address: '13353 Berlin-Wedding, Torfstr. 17',
|
address: '13353 Berlin-Wedding, Torfstr. 17',
|
||||||
latitude: 52.541797,
|
latitude: 52.541797,
|
||||||
longitude: 13.350042
|
longitude: 13.350042
|
||||||
}, {
|
}, {
|
||||||
maxDuration: 10 // minutes
|
maxDuration: 10 // minutes
|
||||||
})
|
}))
|
||||||
.then(console.log)
|
|
||||||
.catch(console.error)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The response may look like this:
|
The result may look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
[
|
[
|
||||||
|
|
|
@ -19,9 +19,7 @@ const dbProfile = require('hafas-client/p/db')
|
||||||
const client = createClient(withThrottling(dbProfile), 'my-awesome-program')
|
const client = createClient(withThrottling(dbProfile), 'my-awesome-program')
|
||||||
|
|
||||||
// Berlin Jungfernheide to München Hbf
|
// Berlin Jungfernheide to München Hbf
|
||||||
client.journeys('8011167', '8000261', {results: 1})
|
await client.journeys('8011167', '8000261', {results: 1})
|
||||||
.then(console.log)
|
|
||||||
.catch(console.error)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
You can pass custom values for the nr of requests (`limit`) per interval into `withThrottling`:
|
You can pass custom values for the nr of requests (`limit`) per interval into `withThrottling`:
|
||||||
|
|
|
@ -27,14 +27,10 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
const client = createClient(vbbProfile)
|
const client = createClient(vbbProfile)
|
||||||
|
|
||||||
// Hauptbahnhof to Heinrich-Heine-Str.
|
// Hauptbahnhof to Heinrich-Heine-Str.
|
||||||
client.journeys('900000003201', '900000100008', {results: 1})
|
const {journeys} = await client.journeys('900000003201', '900000100008', {results: 1})
|
||||||
.then(([journey]) => {
|
|
||||||
// later, fetch up-to-date info on the journey
|
// later, fetch up-to-date info on the journey
|
||||||
client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true})
|
await client.refreshJourney(journeys[0].refreshToken, {stopovers: true, remarks: true})
|
||||||
.then(console.log)
|
|
||||||
.catch(console.error)
|
|
||||||
})
|
|
||||||
.catch(console.error)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`refreshJourney()` will return a *single* [*Friendly Public Transport Format* v2 draft](https://github.com/public-transport/friendly-public-transport-format/blob/3bd36faa721e85d9f5ca58fb0f38cdbedb87bbca/spec/readme.md) `journey`, in the same format as with `journeys()`.
|
`refreshJourney()` will return a *single* [*Friendly Public Transport Format* v2 draft](https://github.com/public-transport/friendly-public-transport-format/blob/3bd36faa721e85d9f5ca58fb0f38cdbedb87bbca/spec/readme.md) `journey`, in the same format as with `journeys()`.
|
||||||
|
|
|
@ -25,7 +25,7 @@ const svvProfile = require('hafas-client/p/svv')
|
||||||
|
|
||||||
const client = createClient(svvProfile, 'my-awesome-program')
|
const client = createClient(svvProfile, 'my-awesome-program')
|
||||||
|
|
||||||
console.log(await client.remarks())
|
await client.remarks()
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
|
@ -21,7 +21,7 @@ const svvProfile = require('hafas-client/p/svv')
|
||||||
|
|
||||||
const client = createClient(svvProfile, 'my-awesome-program')
|
const client = createClient(svvProfile, 'my-awesome-program')
|
||||||
|
|
||||||
console.log(await client.serverInfo())
|
await client.serverInfo()
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
|
@ -40,12 +40,10 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
|
|
||||||
const client = createClient(vbbProfile, 'my-awesome-program')
|
const client = createClient(vbbProfile, 'my-awesome-program')
|
||||||
|
|
||||||
client.stop('900000042101') // U Spichernstr.
|
await client.stop('900000042101') // U Spichernstr.
|
||||||
.then(console.log)
|
|
||||||
.catch(console.error)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The response may look like this:
|
The result may look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
|
|
19
docs/trip.md
19
docs/trip.md
|
@ -13,13 +13,10 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
const client = createClient(vbbProfile, 'my-awesome-program')
|
const client = createClient(vbbProfile, 'my-awesome-program')
|
||||||
|
|
||||||
// Hauptbahnhof to Heinrich-Heine-Str.
|
// Hauptbahnhof to Heinrich-Heine-Str.
|
||||||
client.journeys('900000003201', '900000100008', {results: 1})
|
const {journeys} = client.journeys('900000003201', '900000100008', {results: 1})
|
||||||
.then(([journey]) => {
|
const leg = journeys[0].legs[0]
|
||||||
const leg = journey.legs[0]
|
|
||||||
return client.trip(leg.tripId, leg.line.name)
|
await client.trip(leg.tripId, leg.line.name)
|
||||||
})
|
|
||||||
.then(console.log)
|
|
||||||
.catch(console.error)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
With `opt`, you can override the default options, which look like this:
|
With `opt`, you can override the default options, which look like this:
|
||||||
|
@ -47,12 +44,12 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
|
|
||||||
const client = createClient(vbbProfile)
|
const client = createClient(vbbProfile)
|
||||||
|
|
||||||
client.trip('1|31431|28|86|17122017', 'S9', {when: 1513534689273})
|
console.log(await client.trip('1|31431|28|86|17122017', 'S9', {
|
||||||
.then(console.log)
|
when: 1513534689273,
|
||||||
.catch(console.error)
|
}))
|
||||||
```
|
```
|
||||||
|
|
||||||
The response looked like this:
|
The result looked like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,7 +12,7 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
|
|
||||||
const client = createClient(vbbProfile, 'my-awesome-program')
|
const client = createClient(vbbProfile, 'my-awesome-program')
|
||||||
|
|
||||||
console.log(await client.tripsByName('S1'))
|
await client.tripsByName('S1')
|
||||||
```
|
```
|
||||||
|
|
||||||
With `opt`, you can override the default options, which look like this:
|
With `opt`, you can override the default options, which look like this:
|
||||||
|
@ -42,7 +42,7 @@ With `opt`, you can override the default options, which look like this:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The response may look like this:
|
The result may look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
[
|
[
|
||||||
|
|
Loading…
Add table
Reference in a new issue