From 90f91b81824f8eabe17c7b4b30e2750955cb42bc Mon Sep 17 00:00:00 2001 From: Steve Rogers Date: Sat, 14 Dec 2019 12:44:21 +0000 Subject: [PATCH] Added ability to use Reference Data Endpoint calls with a Staff token --- CHANGES.md | 7 +++++++ README.md | 4 ++-- examples/getStationList.js | 19 +++++++++++++++++++ index.js | 9 ++++++--- package.json | 9 ++++----- 5 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 CHANGES.md create mode 100644 examples/getStationList.js diff --git a/CHANGES.md b/CHANGES.md new file mode 100644 index 0000000..f44a1fe --- /dev/null +++ b/CHANGES.md @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 959121d..cf6e58b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/examples/getStationList.js b/examples/getStationList.js new file mode 100644 index 0000000..2c2226d --- /dev/null +++ b/examples/getStationList.js @@ -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); +}); \ No newline at end of file diff --git a/index.js b/index.js index 2e3ea86..9c320c9 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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" }, diff --git a/package.json b/package.json index 664a519..c02c56c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "ldbsvws-json", - "version": "1.0.0", + "name": "ldbs-json", + "version": "1.1.0", "engines": { "node": ">=7.6" }, @@ -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",