Skip to content
JavaScript client for the deinbus API.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
.editorconfig
.gitignore
.travis.yml
LICENSE
index.js
package-lock.json
package.json
readme.md
test.js

readme.md

deinbus

JavaScript client for the deinbus coach travel API. Complies with the friendly public transport format (FPTF 0.0). Inofficial, using an endpoint by Deinbus. Ask them for permission before using this module in production.

npm version Build Status Greenkeeper badge dependency status dev dependency status license chat on gitter

Installation

npm install --save deinbus

Usage

This package contains data in the Friendly Public Transport Format.

stations

Using deinbus.stations, you can get all stations operated bei Deinbus.

const stations = require('deinbus').stations

stations().then(console.log)

Returns a Promise that will resolve in an array of stations in the Friendly Public Transport Format which looks as follows:

[
    {
        type: 'station',
        id: 'BEZ',
        name: 'Berlin (ZOB)',
        destinations: [
            'ASL',
            'ERF',
            'FRA'
            //
        ]
    }
    //
]

journeys

Using deinbus.journeys, you can get directions and prices for routes from A to B.

const journeys = require('deinbus').journeys

journeys(origin, destination, date = Date.now(), opt = defaults)

const BerlinZOB = 'BEZ'
const Leipzig = 'LPZ'
const date = new Date() // ignores specific time, searches the entire day (based on Europe/Berlin timezone)

journeys(BerlinZOB, Leipzig, date)
.then(console.log)
.catch(console.error)

Returns a Promise that will resolve with an array of journeys in the Friendly Public Transport Format which looks as follows. Note that the legs are not fully spec-compatible, as the schedule is missing and for API-specific reasons, the journey always contains exactly one leg (see also: transfers key).

[
    {
        "type": "journey",
        "id": "BEZ_LPZ_2017-07-13_0715",
        "legs": [
            {
                "origin": "BEZ",
                "destination": "BEZ",
                "departure": "2017-07-13T05:15:00.000Z", // JS Date() object
                "arrival": "2017-07-13T07:25:00.000Z" // JS Date() object
            }
        ],
        "transfers": 0,
        "transferInfo": "",
        "price": {
            "amount": 8.5,
            "currency": "EUR",
            "bookable": true,
            "bookableUntil": "2017-07-13T05:00:00.000Z", // JS Date() object
            "soldOut": false,
            "tickets": [
                {
                    "price": {
                        "amount": 8.5,
                        "currency": "EUR"
                    },
                    "child": false,
                    "description": null
                }
                //
            ]
        },
        "insufficientCapacity": false,
        "minChildBirthdate": "2002-07-13T22:00:00.000Z", // JS Date() object
        "maxUnattendedChildBirthdate": "2011-07-12T22:00:00.000Z" // JS Date() object
    }
    //
]

defaults, partially overridden by the opt parameter, looks like this:

const defaults = {
    passengers: {
        adults: 1,
        children: 0
    }
}

See also

  • FPTF - "Friendly public transport format"
  • FPTF-modules - modules that also use FPTF

Contributing

If you found a bug, want to propose a feature or feel the urge to complain about your life, feel free to visit the issues page.

You can’t perform that action at this time.