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

ldbws-json

v1.0.3

Published

JSON Interface for the National Rail Enquiries Darwin OpenLDBWS SOAP service. Requires a valid token to access services.

Downloads

6

Readme

ldbws-json

ldbws-json is a package that can be used to access the National Rail Enquiries OpenLDBWS web service to query for real time train information. This is the same info that is used to power the Live Departure Boards at UK Railway stations. This service is a SOAP Web service and the ouput is XML, so this package was created to convert these calls into a JSON format.

Notice

This package is no longer be actively maintained, it has been replaced with https://www.npmjs.com/package/ldbs-json which can be used by both USER and STAFF Versions of the API.

Access Token

To use the OpenLDBWS service you MUST supply a valid token, which can be obtained by registering. IF no token, or an invalid one is supplied the call will be rejected. See here for more details on registering as a developer.

Overview

The main class used should be accessed as follows:

const openLDBWS = require('ldbws-json');

then create an instance and pass it a valid access token.

const api = new openLDBWS("{my access token}");

The method to obtain data is call. This is an async method so must be called using either await or as a promise.

const data = await api.call(operation.GET_DEPARTURE_BOARD, params);

or

api.call(operation.GET_DEPARTURE_BOARD, params).then((data) => { /* do something with the data */});

There are 2 other helpers available as well:

  • ldbws-json/LDBWSOperation this is a list of the available OpenLDBWS calls that can be issued
  • ldbws-json/LDBWSRequestData - a set of default JSON objects used to passing the correct request vales for each call

See the usage example below for details on how to use these.

To find out which LDBWSRequestData object to use for each operation see the OpenLDBWS documentation here

Usage

To use this package add it to your project

npm install --save ldbws-json

Then, for example, to get the Departure Board Information for London Victoria (VIC) you would use the following code:

const openLDBWS     = require('ldbws-json');
const operation     = require('ldbws-json/LDBWSOperation');
const requestData   = require('ldbws-json/LDBWSRequestData');
const operationInfo = require('ldbws-json/LDBWSOperationInfo');

// Put a valid Token here
const token = "{PUT_YOUR_ASSIGNED_TOKEN_HERE}";

// Select the operation method we will call and use the helper to extract the result
// use of resultkeys is optional and provided for convienience only
const method = operation.GET_DEPARTURE_BOARD;
const key = operationInfo[method].key;

// populate the required data structure here we use the CRS code for London Victoria
const options = Object.assign({}, requestData.Board);
options.crs = "VIC";

// call the API, wait then return the result
const api = new openLDBWS(token);
api.call(operation.GET_DEPARTURE_BOARD, options).then((board)=>{
    //This should log out London Victoria
    console.log(board[key].locationName);
});

Departure type calls

When using the filterList param for departure based calls set up the list (1 or more) for crs codes as follows:

const options = Object.assign({}, requestData.Departure);
options.crs = "KGX";
options.timeWindow = 120;
options.filterList = ['EDB','ARL'];

In the example this will get the departure list from London Kings Cross to Edinburgh and Arlesey within the next 120 mins.

Mocha Tests

To run the Mocha tests requires a valid Access Token (see above). This is not hard coded in the tests and will need to be passed on the command line when the tests are run. For example if the assigned Access Token is 1234-5678-9876 then the tests can be run similar to:

npm --TOKEN='1234-5678-9876' test

Acknowledgements

  • The LDBWS SOAP Web Service is powered by National Rail Enquiries.