Skip to content

Commit

Permalink
Added ability to use Reference Data Endpoint calls with a Staff token
Browse files Browse the repository at this point in the history
  • Loading branch information
magnatronus committed Dec 14, 2019
1 parent e76b2c8 commit 90f91b8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ldbs-json changelog

## 1.1.0 (Dec 2019)
Updated to allow for access to Staff Reference Data Endpoint calls

## 1.0.0 (Nov 2019)
Initial release
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ api.call("GetDepBoardWithDetails", options).then(board => {
```

There are 2 examples ( one STAFF version and one USER version that can be found in the included *examples* directory of the project).
There are 3 examples ( two STAFF versions and one USER version that can be found in the included *examples* directory of the project). The additional staff version is to access the Reference Data Enpoint calls (this example uses **GetStationList**).

This module is a continuation from my other module https://www.npmjs.com/package/ldbws-json which was only for use with the USER version of the OpenLDBWS web service.


# Acknowledgements
- The LDBS_JSON is powered by National Rail Enquiries.
- The LDBS-JSON module is powered by National Rail Enquiries.
19 changes: 19 additions & 0 deletions examples/getStationList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Simple example code for running the staff version of the DepartureBoard Info to access one of the Reference Data Enpoint API calls "GetStationList"
* NB: You will need a valid Token to access the SV version of the api
*/
const LiveDepartureBoardService = require('../index');
const token = "0000-0000-0000-0000"; // put a valid token here

// Set up the options for the call
const options ={
currentVersion: ''
};

// create a staff version of the API
const api = new LiveDepartureBoardService(token, true);

// make sure we set userRef to true
api.call("GetStationList", options, true).then(list => {
console.log(list);
});
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class LiveDepartureBoardService {
*/
constructor(accessToken = "0000-0000-0000-0000", staffVersion = false) {
this.staffVersion = staffVersion;
this.refUrl = "https://lite.realtime.nationalrail.co.uk/OpenLDBSVWS/ldbsvref.asmx";
this.refTargetNamespace = "http://thalesgroup.com/RTTI/2015-05-14/ldbsv_ref/";
this.baseURL = (staffVersion) ? "https://lite.realtime.nationalrail.co.uk/OpenLDBSVWS/ldbsv12.asmx": "https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb11.asmx";
this.targetNamespace = (staffVersion) ? "http://thalesgroup.com/RTTI/2017-10-01/ldbsv/" : "http://thalesgroup.com/RTTI/2017-10-01/ldb/";
this.accessToken = accessToken;
Expand All @@ -38,12 +40,13 @@ class LiveDepartureBoardService {
* Query the LiveDepartureBoardService for the requested data
* @param {String} method - the LDBWS or LDBSVWS to perform
* @param {Object} options - a JSON object consisting of the key/value pairs for the requested method
* @param {Bool} userRef - only applies for the staff version of the API and allows access to those calls that use the reference data endpoint
*/
async call(method, options) {
const soapCall = new DepartureBoardSoap(this.accessToken, this.targetNamespace, method, options).generateCall();
async call(method, options, useRef = false) {
const soapCall = new DepartureBoardSoap(this.accessToken, (useRef) ? this.refTargetNamespace : this.targetNamespace, method, options).generateCall();
const body = await request({
method: 'POST',
url: this.baseURL,
url: (useRef) ? this.refUrl: this.baseURL,
headers: {
'content-type' : "text/xml"
},
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ldbsvws-json",
"version": "1.0.0",
"name": "ldbs-json",
"version": "1.1.0",
"engines": {
"node": ">=7.6"
},
Expand All @@ -16,15 +16,14 @@
"url": "https://github.com/magnatronus/ldbs-json"
},
"main": "index.js",
"scripts": {
},
"scripts": {},
"keywords": [
"ldbws",
"ldbs",
"openldbws",
"openldbsvws",
"darwin",
"json"
"json"
],
"dependencies": {
"request": "^2.88.0",
Expand Down

0 comments on commit 90f91b8

Please sign in to comment.