tfl-api-wrapper
Advanced tools
Comparing version 0.0.1 to 1.1.0
@@ -1,5 +0,4 @@ | ||
import TfLAPI from './lib/tfl'; | ||
import Line from './lib/line'; | ||
import StopPoint from './lib/stopPoint'; | ||
export default TfLAPI; | ||
export { Line, StopPoint }; | ||
import AirQuality from './lib/airQuality'; | ||
export { AirQuality, Line, StopPoint }; |
@@ -1,9 +0,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StopPoint = exports.Line = void 0; | ||
var tfl_1 = require("./lib/tfl"); | ||
var line_1 = require("./lib/line"); | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.StopPoint = exports.Line = exports.AirQuality = void 0; | ||
var line_1 = require('./lib/line'); | ||
exports.Line = line_1.default; | ||
var stopPoint_1 = require("./lib/stopPoint"); | ||
var stopPoint_1 = require('./lib/stopPoint'); | ||
exports.StopPoint = stopPoint_1.default; | ||
exports.default = tfl_1.default; | ||
var airQuality_1 = require('./lib/airQuality'); | ||
exports.AirQuality = airQuality_1.default; |
@@ -1,40 +0,121 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
'use strict'; | ||
var __awaiter = | ||
(this && this.__awaiter) || | ||
function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { | ||
return value instanceof P | ||
? value | ||
: new P(function (resolve) { | ||
resolve(value); | ||
}); | ||
} | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { | ||
try { | ||
step(generator.next(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var node_fetch_1 = require("node-fetch"); | ||
function rejected(value) { | ||
try { | ||
step(generator['throw'](value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function step(result) { | ||
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); | ||
} | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = | ||
(this && this.__generator) || | ||
function (thisArg, body) { | ||
var _ = { | ||
label: 0, | ||
sent: function () { | ||
if (t[0] & 1) throw t[1]; | ||
return t[1]; | ||
}, | ||
trys: [], | ||
ops: [], | ||
}, | ||
f, | ||
y, | ||
t, | ||
g; | ||
return ( | ||
(g = { next: verb(0), throw: verb(1), return: verb(2) }), | ||
typeof Symbol === 'function' && | ||
(g[Symbol.iterator] = function () { | ||
return this; | ||
}), | ||
g | ||
); | ||
function verb(n) { | ||
return function (v) { | ||
return step([n, v]); | ||
}; | ||
} | ||
function step(op) { | ||
if (f) throw new TypeError('Generator is already executing.'); | ||
while (_) | ||
try { | ||
if (((f = 1), y && (t = op[0] & 2 ? y['return'] : op[0] ? y['throw'] || ((t = y['return']) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)) return t; | ||
if (((y = 0), t)) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: | ||
case 1: | ||
t = op; | ||
break; | ||
case 4: | ||
_.label++; | ||
return { value: op[1], done: false }; | ||
case 5: | ||
_.label++; | ||
y = op[1]; | ||
op = [0]; | ||
continue; | ||
case 7: | ||
op = _.ops.pop(); | ||
_.trys.pop(); | ||
continue; | ||
default: | ||
if (!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && (op[0] === 6 || op[0] === 2)) { | ||
_ = 0; | ||
continue; | ||
} | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { | ||
_.label = op[1]; | ||
break; | ||
} | ||
if (op[0] === 6 && _.label < t[1]) { | ||
_.label = t[1]; | ||
t = op; | ||
break; | ||
} | ||
if (t && _.label < t[2]) { | ||
_.label = t[2]; | ||
_.ops.push(op); | ||
break; | ||
} | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); | ||
continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { | ||
op = [6, e]; | ||
y = 0; | ||
} finally { | ||
f = t = 0; | ||
} | ||
if (op[0] & 5) throw op[1]; | ||
return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var node_fetch_1 = require('node-fetch'); | ||
var TfLAPI = /** @class */ (function () { | ||
@@ -47,3 +128,5 @@ function TfLAPI(config) { | ||
TfLAPI.prototype.sendRequest = function (uri, params, method) { | ||
if (params === void 0) { params = {}; } | ||
if (params === void 0) { | ||
params = {}; | ||
} | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -61,7 +144,8 @@ var options, fetchReq; | ||
}; | ||
return [4 /*yield*/, node_fetch_1.default("https://" + this.host + ":" + this.port + "/" + uri, options)]; | ||
return [4 /*yield*/, node_fetch_1.default('https://' + this.host + ':' + this.port + '/' + uri, options)]; | ||
case 1: | ||
fetchReq = _a.sent(); | ||
return [4 /*yield*/, fetchReq.json()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
return [2 /*return*/, _a.sent()]; | ||
} | ||
@@ -72,3 +156,3 @@ }); | ||
TfLAPI.prototype.sendSerialisedArrayRequest = function (uri, items, options, method) { | ||
return this.sendRequest("" + uri + this.serialiseArray(items), options, method); | ||
return this.sendRequest('' + uri + this.serialiseArray(items), options, method); | ||
}; | ||
@@ -85,6 +169,5 @@ /** | ||
return this.serialiseArray(param); | ||
} else { | ||
return '' + param; | ||
} | ||
else { | ||
return "" + param; | ||
} | ||
}; | ||
@@ -142,4 +225,4 @@ /** | ||
return TfLAPI; | ||
}()); | ||
})(); | ||
exports.default = TfLAPI; | ||
require("../tests/test"); | ||
require('../tests/test'); |
export interface config { | ||
apiKey: string; | ||
appID: string; | ||
app_id: string; | ||
app_key: string; | ||
} |
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -7,9 +7,18 @@ import TfLAPI from './tfl'; | ||
listValidModes(): Promise<any>; | ||
/** Get all severity codes */ | ||
/** Gets a list of all severity codes */ | ||
listSeverityCodes(): Promise<any>; | ||
/** Get all disruption types */ | ||
/** Gets a list of all disruption types */ | ||
listDisruptionCategories(): Promise<any>; | ||
/** Get all service types */ | ||
/** Gets a list of all service types */ | ||
listServiceTypes(): Promise<any>; | ||
/** Gets a list of the stations that serve the given line id */ | ||
listAllStopPoints(line: string): Promise<any>; | ||
/** Gets all lines that serve the given modes. */ | ||
getAllLinesFromMode(modes: Array<string | number>): Promise<any>; | ||
/** Gets the timetable for a specified station on the give line with specified destination */ | ||
getTimetableFromTo(line: string, from: string, to: string): Promise<any>; | ||
/** Gets the inbound timetable for a specified station on the give line */ | ||
getTimetableFromStationIn(line: string, NaPTANID: string): Promise<any>; | ||
/** Gets the outbound timetable for a specified station on the give line */ | ||
getTimetableFromStationOut(line: string, NaPTANID: string): Promise<any>; | ||
} |
@@ -1,17 +0,27 @@ | ||
"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 (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
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"); | ||
'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 (b.hasOwnProperty(p)) d[p] = b[p]; | ||
}; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
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) { | ||
@@ -26,19 +36,36 @@ __extends(Line, _super); | ||
}; | ||
/** Get all severity codes */ | ||
/** Gets a list of all severity codes */ | ||
Line.prototype.listSeverityCodes = function () { | ||
return this.sendRequest('/Line/Meta/Severity', {}, 'GET'); | ||
}; | ||
/** Get all disruption types */ | ||
/** Gets a list of all disruption types */ | ||
Line.prototype.listDisruptionCategories = function () { | ||
return this.sendRequest('/Line/Meta/DisruptionCategories', {}, 'GET'); | ||
}; | ||
/** Get all service types */ | ||
/** Gets a list of all service types */ | ||
Line.prototype.listServiceTypes = function () { | ||
return this.sendRequest('/Line/Meta/ServiceTypes', {}, 'GET'); | ||
}; | ||
/** Gets a list of the stations that serve the given line id */ | ||
Line.prototype.listAllStopPoints = function (line) { | ||
return this.sendRequest("/Line/" + line + "/StopPoints", {}, 'GET'); | ||
return this.sendRequest('/Line/' + line + '/StopPoints', {}, 'GET'); | ||
}; | ||
/** Gets all lines that serve the given modes. */ | ||
Line.prototype.getAllLinesFromMode = function (modes) { | ||
return this.sendRequest('/Line/Mode/' + this.arrayToCSV(modes), {}, 'GET'); | ||
}; | ||
/** 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/' + line + '/Timetable/' + from + '/to/' + to, {}, 'GET'); | ||
}; | ||
/** Gets the inbound timetable for a specified station on the give line */ | ||
Line.prototype.getTimetableFromStationIn = function (line, NaPTANID) { | ||
return this.sendRequest('/Line/' + line + '/Timetable/' + NaPTANID, { direction: 'inbound' }, 'GET'); | ||
}; | ||
/** Gets the outbound timetable for a specified station on the give line */ | ||
Line.prototype.getTimetableFromStationOut = function (line, NaPTANID) { | ||
return this.sendRequest('/Line/' + line + '/Timetable/' + NaPTANID, {}, 'GET'); | ||
}; | ||
return Line; | ||
}(tfl_1.default)); | ||
})(tfl_1.default); | ||
exports.default = Line; |
@@ -1,17 +0,27 @@ | ||
"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 (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
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"); | ||
'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 (b.hasOwnProperty(p)) d[p] = b[p]; | ||
}; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
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 StopPoint = /** @class */ (function (_super) { | ||
@@ -23,10 +33,10 @@ __extends(StopPoint, _super); | ||
StopPoint.prototype.searchStopPoint = function (name, modes) { | ||
return this.sendRequest("/StopPoint/Search/" + name, {}, 'GET'); | ||
return this.sendRequest('/StopPoint/Search/' + name, {}, 'GET'); | ||
}; | ||
/** Get all service arrivals and departures */ | ||
StopPoint.prototype.listStationArrivals = function (id) { | ||
return this.sendRequest("/StopPoint/" + id + "/Arrivals", {}, 'GET'); | ||
return this.sendRequest('/StopPoint/' + id + '/Arrivals', {}, 'GET'); | ||
}; | ||
return StopPoint; | ||
}(tfl_1.default)); | ||
})(tfl_1.default); | ||
exports.default = StopPoint; |
import * as interfaces from './interfaces'; | ||
export default class TfLAPI { | ||
config: interfaces.config; | ||
config: interfaces.config | any; | ||
private readonly host; | ||
private readonly port; | ||
constructor(config: interfaces.config); | ||
sendRequest(uri: string, params: object | undefined, method: string): Promise<any>; | ||
serialiseParam(param: (string | number)[]): string; | ||
serialiseArray(array: Array<string | number>): string; | ||
sendRequest(uri: string, params: any, method: string): Promise<any>; | ||
objectToQuery(params: any): string; | ||
arrayToCSV(arr: Array<string | number>): string; | ||
} |
@@ -1,40 +0,122 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
'use strict'; | ||
var __awaiter = | ||
(this && this.__awaiter) || | ||
function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { | ||
return value instanceof P | ||
? value | ||
: new P(function (resolve) { | ||
resolve(value); | ||
}); | ||
} | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { | ||
try { | ||
step(generator.next(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var node_fetch_1 = require("node-fetch"); | ||
function rejected(value) { | ||
try { | ||
step(generator['throw'](value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function step(result) { | ||
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); | ||
} | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = | ||
(this && this.__generator) || | ||
function (thisArg, body) { | ||
var _ = { | ||
label: 0, | ||
sent: function () { | ||
if (t[0] & 1) throw t[1]; | ||
return t[1]; | ||
}, | ||
trys: [], | ||
ops: [], | ||
}, | ||
f, | ||
y, | ||
t, | ||
g; | ||
return ( | ||
(g = { next: verb(0), throw: verb(1), return: verb(2) }), | ||
typeof Symbol === 'function' && | ||
(g[Symbol.iterator] = function () { | ||
return this; | ||
}), | ||
g | ||
); | ||
function verb(n) { | ||
return function (v) { | ||
return step([n, v]); | ||
}; | ||
} | ||
function step(op) { | ||
if (f) throw new TypeError('Generator is already executing.'); | ||
while (_) | ||
try { | ||
if (((f = 1), y && (t = op[0] & 2 ? y['return'] : op[0] ? y['throw'] || ((t = y['return']) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)) return t; | ||
if (((y = 0), t)) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: | ||
case 1: | ||
t = op; | ||
break; | ||
case 4: | ||
_.label++; | ||
return { value: op[1], done: false }; | ||
case 5: | ||
_.label++; | ||
y = op[1]; | ||
op = [0]; | ||
continue; | ||
case 7: | ||
op = _.ops.pop(); | ||
_.trys.pop(); | ||
continue; | ||
default: | ||
if (!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && (op[0] === 6 || op[0] === 2)) { | ||
_ = 0; | ||
continue; | ||
} | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { | ||
_.label = op[1]; | ||
break; | ||
} | ||
if (op[0] === 6 && _.label < t[1]) { | ||
_.label = t[1]; | ||
t = op; | ||
break; | ||
} | ||
if (t && _.label < t[2]) { | ||
_.label = t[2]; | ||
_.ops.push(op); | ||
break; | ||
} | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); | ||
continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { | ||
op = [6, e]; | ||
y = 0; | ||
} finally { | ||
f = t = 0; | ||
} | ||
if (op[0] & 5) throw op[1]; | ||
return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var node_fetch_1 = require('node-fetch'); | ||
var qs = require('querystring'); | ||
var TfLAPI = /** @class */ (function () { | ||
@@ -47,8 +129,8 @@ function TfLAPI(config) { | ||
TfLAPI.prototype.sendRequest = function (uri, params, method) { | ||
if (params === void 0) { params = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var options, fetchReq; | ||
var FullURL, options, fetchReq; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
FullURL = 'https://' + this.host + ':' + this.port + uri + '?' + qs.stringify(this.config); | ||
options = { | ||
@@ -61,7 +143,11 @@ method: method, | ||
}; | ||
return [4 /*yield*/, node_fetch_1.default("https://" + this.host + ":" + this.port + "/" + uri, options)]; | ||
if (params) { | ||
FullURL = FullURL + '&' + qs.stringify(params); | ||
} | ||
return [4 /*yield*/, node_fetch_1.default(FullURL, options)]; | ||
case 1: | ||
fetchReq = _a.sent(); | ||
return [4 /*yield*/, fetchReq.json()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
return [2 /*return*/, _a.sent()]; | ||
} | ||
@@ -71,15 +157,16 @@ }); | ||
}; | ||
TfLAPI.prototype.serialiseParam = function (param) { | ||
if (Array.isArray(param)) { | ||
return this.serialiseArray(param); | ||
} | ||
else { | ||
return "" + param; | ||
} | ||
TfLAPI.prototype.objectToQuery = function (params) { | ||
var x = Object.keys(params) | ||
.map(function (key) { | ||
return key + '=' + params[key]; | ||
}) | ||
.join('&'); | ||
console.log(x); | ||
return x; | ||
}; | ||
TfLAPI.prototype.serialiseArray = function (array) { | ||
return array && Array.isArray(array) ? array.join(',') : array || ''; | ||
TfLAPI.prototype.arrayToCSV = function (arr) { | ||
return arr.join(','); | ||
}; | ||
return TfLAPI; | ||
}()); | ||
})(); | ||
exports.default = TfLAPI; |
@@ -1,3 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.default = { | ||
@@ -4,0 +4,0 @@ bakerloo: { |
@@ -1,5 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var line_1 = require("../lib/line"); | ||
var stopPoint_1 = require("../lib/stopPoint"); | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var line_1 = require('../lib/line'); | ||
var stopPoint_1 = require('../lib/stopPoint'); | ||
var line = new line_1.default({ | ||
@@ -6,0 +6,0 @@ apiKey: '', |
{ | ||
"name": "tfl-api-wrapper", | ||
"version": "0.0.1", | ||
"version": "1.1.0", | ||
"description": "A Node JS wrapper for the Transport for London API", | ||
@@ -8,9 +8,12 @@ "main": "dist/index.js", | ||
"prepublish": "tsc", | ||
"files": ["dist/**/*"], | ||
"files": [ | ||
"dist/**/*" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"build-docs": "typedoc --options", | ||
"watch": "nodemon dist/lib/index.js" | ||
}, | ||
"keywords": [ | ||
"tfl" | ||
"tfl, api, wrapper, typescript" | ||
], | ||
@@ -21,2 +24,4 @@ "author": "zackaryh8", | ||
"@types/node-fetch": "^2.5.7", | ||
"typedoc": "^0.20.14", | ||
"typedoc-theme-dark": "0.0.5", | ||
"typescript": "^4.1.3" | ||
@@ -23,0 +28,0 @@ }, |
@@ -1,4 +0,10 @@ | ||
# tfl-api-wrapper | ||
A Node JS wrapper for the Transport for London API, made with TypeScript | ||
<p align="center"> | ||
<img width="200" src="https://blog.tfl.gov.uk/wp-content/uploads/2018/05/cropped-logo_roundel-2.png" alt="TfL Logo"> | ||
<h1 align="center">TfL API Wrapper</h1> | ||
</p> | ||
A Node JS wrapper for the Transport for London API and made with TypeScript | ||
## Documentation | ||
[Click here](https://tfldoc.dparture.cc/) | ||
## Example Usage | ||
@@ -8,9 +14,9 @@ | ||
```js | ||
import TfLAPI, { Line } from 'tfl-api-wrapper'; | ||
import { Line } from 'tfl-api-wrapper'; | ||
const client = new TfLAPI({ | ||
apiKey: 'API_KEY_HERE', | ||
appID: '', | ||
}); | ||
const line = new Line(client) | ||
const config = { | ||
app_id: '', | ||
app_key: 'API KEY HERE', | ||
}; | ||
const line = new Line(config) | ||
``` | ||
@@ -21,28 +27,9 @@ | ||
```js | ||
import TfLAPI, { StopPoint } from 'tfl-api-wrapper'; | ||
import { StopPoint } from 'tfl-api-wrapper'; | ||
const client = new TfLAPI({ | ||
apiKey: 'API_KEY_HERE', | ||
appID: '', | ||
}); | ||
const line = new StopPoint(client) | ||
const config = { | ||
app_id: '', | ||
app_key: 'API KEY HERE', | ||
}; | ||
const line = new StopPoint(config) | ||
``` | ||
# Documentation | ||
## Properties | ||
### TfLAPI | ||
config | ||
## Methods | ||
### Line | ||
listValidModes \ | ||
listSeverityCodes \ | ||
listDisruptionCategories \ | ||
listServiceTypes \ | ||
listAllStopPoints | ||
### StopPoint | ||
searchStopPoint \ | ||
listStationArrivals |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
43152
24
1449
0
4
34