Skip to content

Commit

Permalink
added LDBSWSReturn helper
Browse files Browse the repository at this point in the history
updated readme
  • Loading branch information
SpiralArm Consulting Ltd committed Apr 17, 2019
1 parent e4a8459 commit 87e3365
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
21 changes: 21 additions & 0 deletions LDBWSReturn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
/**
* LDBWSReturn.js
* This is a helper that defines the return key for the LDBWS Operation Requests.
*/

const ReturnKey = {
"GetDepartureBoard": "GetStationBoardResult",
"GetDepBoardWithDetails": "GetStationBoardResult",
"GetArrivalBoard": "GetStationBoardResult",
"GetArrBoardWithDetails": "GetStationBoardResult",
"GetArrivalDepartureBoard": "GetStationBoardResult",
"GetArrDepBoardWithDetails": "GetStationBoardResult",
"GetNextDepartures": "DeparturesBoard",
"GetNextDeparturesWithDetails": "DeparturesBoard",
"GetFastestDepartures": "DeparturesBoard",
"GetFastestDeparturesWithDetails": "DeparturesBoard",
"GetServiceDetails": "GetServiceDetailsResult",
}

module.exports = ReturnKey;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ldbws-json",
"version": "1.0.0",
"version": "1.0.1",
"engines": {
"node": ">=7.6"
},
Expand Down
12 changes: 9 additions & 3 deletions readme.MD
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ Then, for example, to get the Departure Board Information for London Victoria (
const openLDBWS = require('ldbws-json');
const operation = require('ldbws-json/LDBWSOperation');
const requestData = require('ldbws-json/LDBWSRequestData');
const resultKeys = require('ldbws-json/LDBWSReturn');
// 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 = resultKeys[method];
// populate the required data structure here we use the CRS code for London Victoria
const options = Object.assign({}, requestData.Board);
options.crs = "VIC";
Expand All @@ -55,20 +61,20 @@ options.crs = "VIC";
const api = new openLDBWS(token);
api.call(operation.GET_DEPARTURE_BOARD, options).then((board)=>{
//This should log out London Victoria
console.log(board.GetStationBoardResult.locationName);
console.log(board[key].locationName);
});
```

# Departure type calls
When using the **filterList** param for *departure* based calls set up the list(1 or more) or **crs** codes as follows:
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.
In the example this will get the departure list from London Kings Cross to Edinburgh and Arlesey within the next 120 mins.



Expand Down
3 changes: 2 additions & 1 deletion test/jsonboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ describe('JSON Board Test', function() {
describe('#Departure Board JSON for Kings Cross', function() {
it('should have London Kings Cross as locationName', async function() {
const method = require('../LDBWSOperation').GET_DEPARTURE_BOARD;
const resultKey = require('../LDBWSReturn')[method];
const options = Object.assign({}, require('../LDBWSRequestData').Board);
options.crs = "KGX";

const api = new OpenLDBWS(token);
const board = await api.call(method, options);

assert.equal(board.GetStationBoardResult.locationName, "London Kings Cross");
assert.equal(board[resultKey].locationName, "London Kings Cross");
});
});
});
3 changes: 2 additions & 1 deletion test/jsondeparture.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ describe('JSON Departure Test', function() {
describe('#Next Departures JSON for Kings Cross', function() {
it('should have London Kings Cross as locationName', async function() {
const method = require('../LDBWSOperation').GET_NEXT_DEPARTURES;
const resultKey = require('../LDBWSReturn')[method];
const options = Object.assign({}, require('../LDBWSRequestData').Departure);
options.crs = "KGX";
options.filterList = ['EDB', 'LET'];
const api = new OpenLDBWS(token);
const board = await api.call(method, options);
assert.equal(board.DeparturesBoard.locationName, "London Kings Cross");
assert.equal(board[resultKey].locationName, "London Kings Cross");
});
});
});

0 comments on commit 87e3365

Please sign in to comment.