tfl-api-wrapper
Version:
A Node JS wrapper for the Transport for London API
117 lines (116 loc) • 6.25 kB
JavaScript
;
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");
var Line = /** @class */ (function (_super) {
__extends(Line, _super);
function Line(config) {
return _super.call(this, config) || this;
}
/** Get all valid modes */
Line.prototype.getModes = function () {
return this.sendRequest('/Line/Meta/Modes', {});
};
/** Gets a list of all severity codes */
Line.prototype.getSeverityCodes = function () {
return this.sendRequest('/Line/Meta/Severity', {});
};
/** Gets a list of all disruption types */
Line.prototype.getDisruptionCategories = function () {
return this.sendRequest('/Line/Meta/DisruptionCategories', {});
};
/** Gets a list of all service types */
Line.prototype.getServiceTypes = function () {
return this.sendRequest('/Line/Meta/ServiceTypes', {});
};
/** Gets a list of the stations that serve the given line id */
Line.prototype.getAllStopPoints = function (line) {
return this.sendRequest("/Line/".concat(line, "/StopPoints"), {});
};
/**
* Gets all lines that serve the given modes
* @param modes An array of modes e.g. tube, tram
*/
Line.prototype.getAllByModes = function (modes) {
return this.sendRequest("/Line/Mode/".concat(tfl_1.default.arrayToCSV(modes)), {});
};
/**
* Gets the line status of for given line ids e.g Minor Delays
* @param lines A list of line ids e.g. victoria, circle, N133
* @param detail Include details of the disruptions that are causing the line status including the affected stops and routes
* @param startDate
* @param endDate
*/
Line.prototype.getStatusByLine = function (lines, detail, startDate, endDate) {
if (detail === void 0) { detail = false; }
if (!startDate || !endDate) {
return this.sendRequest("/Line/".concat(tfl_1.default.arrayToCSV(lines), "/Status"), { detail: detail });
}
else {
return this.sendRequest("/Line/".concat(tfl_1.default.arrayToCSV(lines), "/Status/").concat(tfl_1.default.convertDate(startDate), "/to/").concat(tfl_1.default.convertDate(endDate)), { detail: detail });
}
};
/**
* Gets the line status of for all lines for the given modes
* @param modes A comma-separated list of modes to filter by. e.g. tube,dlr
* @param detail Include details of the disruptions that are causing the line status including the affected stops and routes
* @param severityLevel If specified, ensures that only those line status(es) are returned within the lines that have disruptions with the matching severity level
*/
Line.prototype.getStatusByModes = function (modes, detail, severityLevel) {
return this.sendRequest("/Line/Mode/".concat(tfl_1.default.arrayToCSV(modes), "/Status"), { detail: detail, severityLevel: severityLevel });
};
/** Gets the timetable for a specified station on the give line with specified destination */
Line.prototype.getTimetableFromTo = function (line, from, to) {
return this.sendRequest("/Line/".concat(line, "/Timetable/").concat(from, "/to/").concat(to), {});
};
/**
* Gets the inbound timetable for a specified station on the give line
*
* @param line Id of the line e.g. 'victoria'
* @param NaptanID Id of the stop (station naptan code e.g. 940GZZLUASL)
* @param direction What direction you want the timetable for. Leave blank for outbound or 'inbound'
*/
Line.prototype.getTimetableFromStation = function (line, NaPTANID, direction) {
return this.sendRequest("/Line/".concat(line, "/Timetable/").concat(NaPTANID), { direction: direction });
};
/** Get the list of arrival predictions for given line ids based at the given stop
* @param ids list of line ids e.g. ['victoria','circle','N133']
* @param NaptanID Id of stop to get arrival predictions for (station naptan code e.g. 940GZZLUASL)
* @param direction Optional. The direction of travel. Can be inbound or outbound or all. Default: all
* @param destinationStationId Optional. Id of destination stop
*/
Line.prototype.getArrivalsByNaptan = function (ids, NaptanID, direction, destinationStationId) {
if (direction === void 0) { direction = 'all'; }
return this.sendRequest("/Line/".concat(tfl_1.default.arrayToCSV(ids), "/Arrivals/").concat(NaptanID), { direction: direction, destinationStationId: destinationStationId });
};
/**
* Get disruptions for the given line ids
* @param ids list of line ids e.g. ['victoria','circle','N133']
*/
Line.prototype.getDistruptionsByID = function (ids) {
return this.sendRequest("/Line/".concat(tfl_1.default.arrayToCSV(ids), "/Disruption"), {});
};
/**
* Get all valid routes for all lines, including the name and id of the originating and terminating stops for each route.
* @param serviceTypes A comma seperated list of service types to filter on. Supported values: Regular, Night. Defaulted to 'Regular' if not specified
*/
Line.prototype.getAllValidRoutes = function (serviceTypes) {
return this.sendRequest("/Line/Route", { serviceTypes: serviceTypes });
};
return Line;
}(tfl_1.default));
exports.default = Line;