npm package: @nederlandse-spoorwegen/travel-information-api
Description: A wrapper for the NS travel information API.
Author: NS Reisinformatie online
Latest version: 1.0.1
Deprecated: Please wait until the release, API keys not yet available

# NS API
The NS API package provides a high level wrapper for the NS travel information API.

# Installation
```sh
    npm install @nederlandse-spoorwegen/travel-information-api
````

# Development
Clone the repository and run the following commands:
```sh
    npm install
    npm run dev
```
A development server is now running allowing you to test your changes directly on your machine. 
# Usage
For more documentation about parameters and responses please refer to the [NS developer portal](https://apiportal.ns.nl/)

### Error handling
All errors are returned directly to the user and are __not__ handled by the wrapper.

### Create api instance
Create a new api instance using your key and optional base url. 
By default the base url is correctly set and you do not need to specify it.
```sh
    const api = new NsApi("YourKey")
````
All calls return a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
### Departures
Get a list of departure by station code or UIC code.
Note that when both a station code and uic code have been specified the station code has the higher priority.
```sh
    const departures = api.departures()
    
    const params = {
        station: "UT", // Utrecht Centraal
        uicCode: "8400058" // Amsterdam Centraal
    }
    
    departures.list(params)
        .then((result) => {
            // Handle successful response
        })
        .catch((error) => {
            // Handle error
        })
````

### Disruptions
##### List of disruptions
Get a list of all disruptions.
```sh
    const disruptions = api.disruptions()
    
    const params = {
        type: "storing"
        actual: false,
        lang: "en"
    }
    
    disruptions.list(params).then((result) => {
                
    })
````
##### Disruptions by station
Get a list of disruptions by providing a station code.
```sh
    disruptions.byStation("UT").then((result) => {
                
    })
````
##### Disruptions by id
Get a specific disruptions by using an id.
```sh
    disruptions.byId("SomeId").then((result) => {
                
    })
````
### Prices
Get information about journey fares and discounts.
Dates should us the following format: 'yyyy-MM-dd'
```sh
    const prices = api.prices()
    
    const params = {
        fromStation: "ASD", // Amsterdam Centraal
        toStation: "UT", // Utrecht Centraal
        plannedFromTime: "2018-10-14",
    };
    
    prices.get(params).then((result) => {
                
    })
````

### Stations
Information about stations.
```sh
    const stations = api.stations()
    
    stations.list().then((result) => {
                
    })
````

### Trips
Returns travel advice information.
```sh
    const trips = api.trips();

    const params = {
        fromStation: "ASD", // Amsterdam Centraal
        toStation: "UT", // Utrecht Centraal
    };
    
    trips.get(params).then((result) => {
                
    })
````