Code Monkey home page Code Monkey logo

nodejs-ns-api's Introduction

ns-api

Access public transit data from Nederlandse Spoorwegen API with node.js

Changelog Build Status Coverage Status

To use this module you need API access credentials, which you can request at Here (Dutch).

Example

const NSAPI = require ('ns-api');
const ns = new NSAPI ({
  key: 'abc123',
});

// Output w/o limits
function out (data) {
  console.dir (data, {
    depth: null,
    colors: true,
  });
}

// Get travel advise
ns.getTrips ({
  fromStation: 'UT',
  toStation: 'AMF',
})
  .then (out)
  .catch (console.error)
;

Installation

npm i ns-api

Configuration

param type default description
key string One of your API keys
[timeout] number 8000 Request time out in ms
const NSAPI = require ('ns-api');
const ns = new NSAPI ({
  key: 'abc123',
});

Methods

Each method returns a Promise, so make sure to catch the errors properly.

When a method takes arguments they are only accepted in object notation. This way the order no longer matters and it makes it easier to reuse them.

methodName ({ one, two });

I'm not going to outline to full possibilities of each method here, only the parts that adjust the API response or make the request easier. Read the API documentation links to find all available parameters that each method can take.

Reisinformatie

getAllStations

List of all stations

ns.getAllStations()
  .then (data => data.filter (station => station.land === 'NL'))
  .then (data => console.table (data, ['code', 'stationType']))
  .catch (console.error)
;

API documentation

getArrivals

List of arrivals at a station. It requires a station or uicCode.

parameter type description
[dateTime] Date or string Limit to starting time, will be converted to the right format
ns.getArrivals ({
  dateTime: '2019-05-10',
  station: 'UT',
})
  .then (data => console.table (data, ['name', 'origin', 'actualDateTime']))
  .catch (console.error)
;

API documentation

getCalamities

List of all current calamities

parameter type description
[lang] string Text language
ns.getArrivals ({ lang: 'en' })
  .then (console.log)
  .catch (console.error)
;

API documentation

getDepartures

List all departures at a station. It requires a station or uicCode.

parameter type description
[dateTime] Date or string Limit to starting time, will be converted to the right format
ns.getDepartures ()
  .then (console.log)
  .catch (console.error)
;

API documentation

getDisruptions

List of disruptions/maintenance.

parameter type description
[actual] boolean Only return disruptions within 2 hours
ns.getDisruptions()
  .then (data => console.table (data, ['titel']))
  .catch (console.error)
;

API documentation

getStationDisruption

List of disruptions at a station

parameter type description
[dateTime] Date or string Limit to starting time, will be converted to the right format
ns.getStationDisruption ({ dateTime: '2019-05-10' })
  .then (data => console.table (data, ['titel']))
  .catch (console.error)
;

API documentation

getDisruption

Get details about one disruption

parameter type description
type string Disruption type
id string Disruption object ID
ns.getDisruption ({
  type: 'maintenance',
  id: '7001000',
})
  .then (console.log)
  .catch (console.error)
;

API documentation

getTrips

Get a list of travel advises

parameter type description
[dateTime] Date or string Limit to starting time, will be converted to the right format
ns.getTrips ({
  dateTime: '2019-05-10 17:40',
  fromStation: 'Amersfoort',
  toStation: 'Den Haag',
})
  .then (console.log)
  .catch (console.error)
;

API documentation

getTrip

Get a specific travel advise

parameter type description
ctxRecon string Trip ctxRecon from getTrips()
ns.getTrip ({ ctxRecon: 'abc123' })
  .then (console.log)
  .catch (console.error)
;

API documentation

getPrice

Get pricing for travel between two stations.

parameter type description
fromStation string Station name or ID
toStation string Station name or ID
ns.getPrices ({
  fromStation: 'AMF',
  toStation: 'Den Haag',
})
  .then (console.log)
  .catch (console.error)
;

API documentation

getJourney

Get information about a specific journey. You can find the id in the trip data from getTrip() at trip.legs[].journeyDetail[].link.uri. Just use that whole path.

parameter type description
id string Journey ID
ns.getJourney ({
  id: 'HARP_S2S-1|3824|0|784|8052021',
})
  .then (console.log)
  .catch (console.error)
;

API documentation

Places

placesList

Search for places. Returns an array.

argument type description
parameters object See API docs
ns.placesList ({
  q: 'utrecht cs',
});

API documentation

placesGet

Get details about one place. Returns an object.

parameter type description
type string Place type, ex: stationV2
id string Place ID, ex: AMF
[lang] string Response language
ns.placesGet ({
  type: 'stationV2',
  id: 'AMF',
});

API documentation

placesOvfiets

Get a list of OV Fiets locations. Returns an array.

parameter type description
[station_code] string Filter by station
ns.placesOvfiets ({
  station_code: 'AMF',
});

API documentation

Unlicense

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to https://unlicense.org/

Author

Franklin | Buy me a coffee

nodejs-ns-api's People

Contributors

dependabot[bot] avatar fvdm avatar greenkeeper[bot] avatar greenkeeperio-bot avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nodejs-ns-api's Issues

An in-range update of dotest is breaking the build 🚨


🚨 Reminder! Less than one month left to migrate your repositories over to Snyk before Greenkeeper says goodbye on June 3rd! πŸ’œ πŸššπŸ’¨ πŸ’š

Find out how to migrate to Snyk at greenkeeper.io


The devDependency dotest was updated from 2.6.2 to 2.7.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

dotest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).
  • βœ… coverage/coveralls: First build on greenkeeper/dotest-2.7.0 at 90.385% (Details).

Commits

The new version differs by 9 commits.

  • ce306a3 2.7.0
  • 13ee536 Docs(changelog): Update changelog
  • f2e1fe4 Test(config): Add OS to Travis config
  • a49d391 Test(config): Update Travis node versions
  • 2209dab Test(config): Modernized Travis config
  • 06ccbcc Breaking: Removed Codacy support
  • 3900870 Chore(package): Minimum node version 10
  • d1f58db Chore(package): Update dependencies
  • 7002580 Chore(dev): Update editorconfig

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Uitschakelen van oude disruptions API vanaf 4 augustus 2021

From their email:

(For English, see below)

Goedendag,

Vanuit NS zijn we continu bezig met het verbeteren van onze APIs. Daarom willen we u erop attenderen dat in onze reisinformatie-api versie 2 van de disruptions endpoints vanaf 4 augustus 2021 uitgeschakeld zal worden. Het gaat om de volgende endpoints:

https://gateway.apiportal.ns.nl/reisinformatie-api/api/v2/disruptions
https://gateway.apiportal.ns.nl/reisinformatie-api/api/v2/disruptions/{id}
https://gateway.apiportal.ns.nl/reisinformatie-api/api/v2/disruptions/station/{stationCode}

Deze endpoints worden vervangen door de volgende v3 endpoints:

https://gateway.apiportal.ns.nl/reisinformatie-api/api/v3/disruptions
https://gateway.apiportal.ns.nl/reisinformatie-api/api/v3/disruptions/{type}/{id}
https://gateway.apiportal.ns.nl/reisinformatie-api/api/v3/disruptions/station/{stationCode}

Deze nieuwe endpoints zijn nu al beschikbaar. We raden daarom aan om zo snel mogelijk te migreren naar deze nieuwe endpoints. De andere endpoints in de reisinformatie-api blijven gewoon werken, zoals ze nu ook al doen.

De reden voor het introduceren van het nieuwe endpoint is het feit dat verstoringen en werkzaamheden nu opgedeeld kunnen worden in meerdere tijdvakken. Er kunnen bijvoorbeeld werkzaamheden plaatsvinden in een weekend, waarbij de maatregelen op zaterdag anders zijn dan die op zondag. In het oude endpoint werd dit alleen in de tekst vermeld. In het nieuwe endpoint zullen er voor deze werkzaamheid meerdere tijdvakken worden teruggegeven.Daarnaast zijn de velden in de response meer consistent gemaakt. Let op bij het migreren naar de nieuwe URL dat er door deze wijzigingen wel aanpassingen zitten in het response object. Een voorbeeld van een response is te vinden in de bijlage.

Meer informatie vindt u op het API portaal. Mochten er nog vragen zijn voor het migreren dan horen we dat graag.

Groeten,

NS MLab


Dear reader,

As NS we are continuously working on improving our APIs. In that light, we want to announce the deprecation of some of our endpoints. As of August 4 2021 we will no longer support version 2 of our disruptions endpoints in our travel information api (reisinformatie-api). These deprecated endpoints include:

https://gateway.apiportal.ns.nl/reisinformatie-api/api/v2/disruptions
https://gateway.apiportal.ns.nl/reisinformatie-api/api/v2/disruptions/{id}
https://gateway.apiportal.ns.nl/reisinformatie-api/api/v2/disruptions/station/{stationCode}

These endpoints are being replaced by the following new endpoints:

https://gateway.apiportal.ns.nl/reisinformatie-api/api/v3/disruptions
https://gateway.apiportal.ns.nl/reisinformatie-api/api/v3/disruptions/{type}/{id}
https://gateway.apiportal.ns.nl/reisinformatie-api/api/v3/disruptions/station/{stationCode}

These new endpoints are already available. We recommend to migrate to these new endpoints as soon as possible. All other endpoints in the travel information api will remain the same.

The reason for the introduction of a new endpoint lies in the fact that the structure of the data for disruptions and maintenance has changed. They can now be divided into multiple timespans. For example, maintenance in a weekend could have consequences on Saturday, which are different from the consequences on Sunday. The old endpoint returned this information only in text. The new endpoint will return multiple timespans for such a situation. Apart from these changes, the fields in the response have been updated to be more consistent. Because of these changes, the response object has changed. An example of the new format can be found in the attached json file.

For more information, please check the API documentation on the API portal. If there are any questions remaining, please let us know.

Kind regards,

NS MLab

Rewrite test script

  • Tests β€˜n checks
  • Run successfully on Node 8, 10 and 12
  • Healthy coverage report
  • Healthy npm audit

Fix API interface changes

The API has undergone a series of undocumented interface changes, causing problems with this library.

Response error: API_KEY_NOT_ALLOWED_TO_PLAN_DOOR_TO_DOOR

Trying to use some of the lib's methods like getAllStations all getTrips, but get this: error

{
    "timestamp": "2021-05-08T08:27:36+0000",
    "path": "/api/v3/trips",
    "message": "Bad Request",
    "requestId": "6bbad54b-db8c-43e0-8f33-844f3eec3dc6",
    "code": 400,
    "errors": [
        {
            "message": "Met deze API key mogen geen deur-tot-deur adviezen opgevraagd worden πŸ™",
            "type": "API_KEY_NOT_ALLOWED_TO_PLAN_DOOR_TO_DOOR",
            "lang": "nl"
        }
    ]
}

This is strange because this key works with https://gateway.apiportal.ns.nl/places-api/v2/places api.
Any ideas?

Vertrekspoor ns.reisadvies incompleet

Het vertrekspoor nummer ontbreekt in de reisadviezen. De oorzaak ligt in de node-xml2json module, deze negeert de xml tag waarde als de tag attributes heeft.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.