npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

national-rail-darwin

v1.0.8

Published

national rail's darwin soap based api

Downloads

324

Readme

national-rail-darwin

Standard - JavaScript Style Guide Test Status

Introduction

national-rail-darwin aims to give you json object representations of the SOAP responses from National Rail's Darwin api. Details of the api can be found here

Currently only CRS codes are supported, a future update will allow full station names to be used. You can find a complete list of CRS codes on the National Rail website .

Installation

npm install national-rail-darwin

Usage

All 11 requests exposed by the Darwin api are available in national-rail-darwin

  • getDepartureBoard(crsCode, options, callback)
  • getArrivalsBoard(crsCode, options, callback)
  • getArrivalsBoardWithDetails(crsCode, options, callback)
  • getArrivalsDepartureBoard(crsCode, options, callback)
  • getArrivalsDepartureBoardWithDetails(crsCode, options, callback)
  • getServiceDetails(serviceId, callback)
  • getNextDeparture(crsCode, destinationCrsCode, options, callback)
  • getNextDepartureWithDetails(crsCode, destinationCrsCode, options, callback)
  • getDepartureBoardWithDetails(crsCode, options, callback)
  • getFastestDeparture(crsCode, destinationCrsCode, options, callback)
  • getFastestDepartureWithDetails(crsCode, destinationCrsCode, options, callback)

Additional functions

  • getStationDetails(Station, callback)

Your api token can either be provided when the client is created or picked up from the environment variable DARWIN_TOKEN.

  var Rail = require('national-rail-darwin')
  var rail = new Rail() // or -> new Rail(DARWIN_TOKEN)

Options

Some functions take an options object. See the specific method definitions for details of these.

Methods

All methods return arrays of basic service objects of the form:

{
  sta: '23:57',
  eta: 'On time',
  std: '23:57',
  etd: 'On time',
  platform: '2',
  delayReason: null,
  origin: {
    name:<stationname>,
    crs:<crsCode>
  },
  destination: {
    name:<stationname>,
    crs:<crsCode>
  },
  length: '5',
  serviceId: 'xxxxxxxxxxxxxxxx+xx/xxx=='
}

getDepartureBoard

rail.getDepartureBoard('WAT', {}, function(err,result){
    //do stuff
})

Gets all public departures for the supplied station within 2 hours. Options: 'destination': Only show trains that call at the supplied station. 'rows': Maximum number of services to retrieve (1 - 149).

getArrivalsBoard

rail.getArrivalsBoard('PUT', {}, function(err, result){
    //do stuff
})

Similar to getDepartureBoard but shows arrivals within the next two hours. Options: 'destination': Only show trains that have called at the supplied station. 'rows': Maximum number of services to retrieve.

getArrivalsBoardWithDetails

rail.getArrivalsBoardWithDetails('PUT', {}, function(err, result){
    //do stuff
})

Adds service details including previous calling points to the getArrivalsBoardResult. Options: 'destination': Only show trains that have called at the supplied station. 'rows': Maximum number of services to retrieve.

getArrivalsDepartureBoard

rail.getArrivalsDepartureBoard('PUT', {}, function(err, result){
    //do stuff
})

Returns all public arrivals and departures for the supplied CRS code within 2 hours. Options: 'destination': Only show trains that have called at the supplied station. 'rows': Maximum number of services to retrieve.

getArrivalsDepartureBoardWithDetails

rail.getArrivalsDepartureBoardWithDetails('PUT', {}, function(err, result){
    //do stuff
})

Returns array of train services with both previous and subsequent calling points included for each service. Options: 'destination': Only show trains that have called at the supplied station. 'rows': Maximum number of services to retrieve.

getServiceDetails

rail.getServiceDetails('SERVICE ID', function(err, result){
    //do stuff
})

Gets detailed information about a particular service relative to the station that generated the serviceId. ServiceId is returned from other calls such as getDepartureBoard or getNextDeparture. The object returns includes all calling points of the service requested. The data is only available while the particular service is showing on the station departure board. This is normally for up to two minutes after the service is expected to depart.

getNextDeparture

rail.getNextDeparture(crsCode, destinationCrsCode, {}, function(err, result){
    //do stuff
})

Returns the next train leaving from supplied station calling at the destination CRS Code.

getNextDepartureWithDetails

rail.getNextDepartureWithDetails(crsCode, destinationCrsCode, {}, function(err, result){
    //do stuff
})

Returns the next train leaving from supplied station calling at the destination CRS Code within two hours including subsequent calling points.

getDepartureBoardWithDetails

rail.getDepartureBoardWithDetails('WAT', {}, function(err,result){
    //do stuff
})

Adds a list of future calling points to the standard departure board response. 'destination': Only show trains that call at the supplied station. 'rows': Maximum number of services to retrieve.

getFastestDeparture

rail.getFastestDeparture('from', 'destination crs', {}, function(err,result){
    //do stuff
})

Returns the service with the earliest arrival time at the destination station leaving from the supplied station.

getFastestDepartureWithDetails

rail.getFastestDepartureWithDetails('from', 'destination crs', {}, function(err,result){
    //do stuff
})

Same response as getFastestDeparture but includes service details such as previous and subsequent calling points.

getStationDetails

rail.getStationDetails('Leeds', function(err,result){
    //do stuff
})

Look up station details including CRSCode from the full station name

Command Line

national-rail-darwin now provides a command line tool, darwin, for querying the Darwin API. All Darwin requests are accessible via this tool. Install globally and run

darwin --help

for usage details.

To authenticate using the command line you can either specify your API token using the --token flag or set DARWIN_TOKEN as an environment variable.

You can print the result as raw JSON by using the --json option if you want to manipulate the output with something like jq.

For example:

darwin --json -t XXX arr-board ANZ | jq '.trainServices[]'