tfl-api-wrapper
Version:
A Node JS wrapper for the Transport for London API
184 lines (183 loc) • 9.19 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var tfl_1 = require("./tfl");
// import * as IStopPoint from './interfaces/stopPoint';
var StopPoint = /** @class */ (function (_super) {
__extends(StopPoint, _super);
function StopPoint(config) {
return _super.call(this, config) || this;
}
/**
* Gets the list of available StopPoint additional information categories
*/
StopPoint.prototype.getCategories = function () {
return this.sendRequest("/StopPoint/Meta/Categories", {});
};
/**
* Gets the list of available StopPoint types
*/
StopPoint.prototype.getTypes = function () {
return this.sendRequest("/StopPoint/Meta/StopTypes", {});
};
/**
* Gets the list of available StopPoint modes
*/
StopPoint.prototype.getModes = function () {
return this.sendRequest("/StopPoint/Meta/Modes", {});
};
/**
* Gets a list of StopPoints corresponding to the given list of stop ids
* @param ids A list of stop point ids (station naptan code e.g. 940GZZLUASL).
* @param includeCrowdingData Include the crowding data (static). To Filter further use: /StopPoint/{ids}/Crowding/{line}
*/
StopPoint.prototype.getByIDs = function (ids, includeCrowdingData) {
return this.sendRequest("/StopPoint/".concat(tfl_1.default.arrayToCSV(ids)), { includeCrowdingData: includeCrowdingData });
};
/**
* Gets all stop points of a given type
* @param types A list of valid stop types can be obtained from the StopPoint/meta/stoptypes endpoint
*/
StopPoint.prototype.getAllByStopType = function (types) {
return this.sendRequest("/StopPoint/Type/".concat(tfl_1.default.arrayToCSV(types)), {});
};
/**
* Gets the service types for a given Stop Point
* @param id
* @param lineIds
* @param modes
*/
StopPoint.prototype.getServiceTypesByID = function (id, lineIds, modes) {
return this.sendRequest("/StopPoint/ServiceTypes", { id: id, lineIds: lineIds, modes: modes });
};
/**
* Search StopPoints by their common name. Will not return a valid NaPTAN for HUB
* @param name Name of station
* @param modes Eg. tfl, dlr
*/
StopPoint.prototype.search = function (name, modes) {
return this.sendRequest("/StopPoint/Search/".concat(name), { modes: modes });
};
/**
* Get all service arrivals
* @param id A StopPoint id (station naptan code e.g. 940GZZLUAS)
*/
StopPoint.prototype.getStationArrivals = function (id) {
var x = 'test';
var y = 'test';
return this.sendRequest("/StopPoint/".concat(id, "/Arrivals"), { x: x, y: y });
};
/**
*
* @param id A StopPoint id (station naptan code e.g. 940GZZLUAS)
* @param lineIds List of line ids e.g. tfl-rail, london-overground, thameslink
*/
// getArrivalDepartures(id: string, lineIds: Array<string>) {
// return this.sendRequest(`/StopPoint/${id}/ArrivalsDepartures`, { lineIds }, 'GET');
// }
/**
* Gets all disruptions for the specified StopPointId, plus disruptions for any child Naptan records it may have
* @param ids A list of StopPoint ids (station naptan code e.g. 940GZZLUAS)
* @param getFamily Specify true to return disruptions for entire family, or false to return disruptions for just this stop point. Defaults to false.
* @param includeRouteBlockedStops
* @param flattenResponse Specify true to associate all disruptions with parent stop point. (Only applicable when getFamily is true)
*/
StopPoint.prototype.getDisruptionsByID = function (ids, getFamily, includeRouteBlockedStops, flattenResponse) {
return this.sendRequest("/StopPoint/".concat(tfl_1.default.arrayToCSV(ids), "/Disruption"), {
getFamily: getFamily,
includeRouteBlockedStops: includeRouteBlockedStops,
flattenResponse: flattenResponse
}, 'GET');
};
/**
* Gets a distinct list of disrupted stop points for the given modes
* @param modes An array of modes e.g. ['tube', 'dlr']
* @param includeRouteBlockedStops
*/
StopPoint.prototype.getDisruptionsByMode = function (modes, includeRouteBlockedStops) {
return this.sendRequest("/StopPoint/Mode/".concat(tfl_1.default.arrayToCSV(modes), "/Disruption"), { includeRouteBlockedStops: includeRouteBlockedStops });
};
/**
* Gets Stop points that are reachable from a station/line combination
* @param id A StopPoint id (station naptan code e.g. 940GZZLUAS)
* @param lineID Line id of the line to filter by (e.g. victoria)
* @param serviceTypes List of service types to filter on. Supported values: Regular, Night. Defaulted to 'Regular'.
*/
StopPoint.prototype.getReachableStationsByID = function (id, lineID, serviceTypes) {
if (serviceTypes === void 0) { serviceTypes = ['Regular']; }
return this.sendRequest("/StopPoint/".concat(id, "/CanReachOnLine/").concat(lineID), { serviceTypes: tfl_1.default.arrayToCSV(serviceTypes) });
};
/**
* Get the route sections for all the lines that service the given stop point id
* @param id A StopPoint id (station naptan code e.g. 940GZZLUAS)
* @param serviceTypes List of service types to filter on. Supported values: Regular, Night. Defaulted to 'Regular'.
*/
StopPoint.prototype.getRouteSectionByID = function (id, serviceTypes) {
if (serviceTypes === void 0) { serviceTypes = ['Regular']; }
return this.sendRequest("/StopPoint/".concat(id, "/ "), { serviceTypes: tfl_1.default.arrayToCSV(serviceTypes) });
};
/**
* Gets a list of StopPoints within {radius} by the specified criteria
* @param stopTypes a list of stopTypes that should be returned.
* @param radius The radius of the bounding circle in metres (default : 200)
* @param useStopPointHierarchy Re-arrange the output into a parent/child hierarchy.
* @param modes The list of modes to search (e.g. tube, dlr)
* @param categories an optional list of comma separated property categories to return in the StopPoint's property bag. If null or empty, all categories of property are returned. Pass the keyword "none" to return no properties.
* @param returnLines True to return the lines that each stop point serves as a nested resource.
* @param latitude
* @param longitude
*/
StopPoint.prototype.getInRadius = function (stopTypes, radius, useStopPointHierarchy, modes, categories, returnLines, latitude, longitude) {
if (radius === void 0) { radius = 200; }
return this.sendRequest("/StopPoint", {
stopTypes: tfl_1.default.arrayToCSV(stopTypes),
radius: radius,
useStopPointHierarchy: useStopPointHierarchy,
modes: tfl_1.default.arrayToCSV(modes),
categories: tfl_1.default.arrayToCSV(categories),
returnLines: returnLines,
lat: latitude,
lon: longitude
});
};
/**
* Gets a StopPoint for a given sms code.
* @param smsID A 5-digit Countdown Bus Stop Code e.g. 73241, 50435, 56334.
* @param output If set to "web", a 302 redirect to relevant website bus stop page is returned. All other values are ignored.
*/
StopPoint.prototype.getBySMSCode = function (smsID, output) {
return this.sendRequest("/StopPoint/Sms/".concat(smsID), { output: output });
};
/**
* Gets a list of taxi ranks corresponding to the given stop point id
* @param id A StopPoint id (station naptan code e.g. 940GZZLUAS)
*/
StopPoint.prototype.getTaxiRanksByID = function (id) {
return this.sendRequest("/StopPoint/".concat(id, "/TaxiRanks"), {});
};
/**
* Get car parks corresponding to the given stop point id
* @param id A StopPoint id (station naptan code e.g. 940GZZLUAS)
*/
StopPoint.prototype.getCarParksByID = function (id) {
return this.sendRequest("/StopPoint/".concat(id, "/CarParks"), {});
};
return StopPoint;
}(tfl_1.default));
exports.default = StopPoint;
var x = new StopPoint('');
x.getStationArrivals('940GZZLUKSX');