diff --git a/ns-api/index.d.ts b/ns-api/index.d.ts new file mode 100644 index 0000000000..db66f109f3 --- /dev/null +++ b/ns-api/index.d.ts @@ -0,0 +1,66 @@ +// Type definitions for ns-api 2.0 +// Project: https://github.com/fvdm/nodejs-ns-api#readme +// Definitions by: Sander Koenders +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = nsApi; +declare function nsApi(conf: nsApi.Configuration): nsApi; + +interface nsApi { + /** + * Vertrektijden - departure times + * + * @callback callback + * @param station {string} - Station ID + * @param callback {function} - `function (err, data) {}` + * @returns {void} + */ + vertrektijden(station: string, callback: (err: string, data: {}) => void): void; + + /** + * Reisadvies - travel advise + * + * @callback callback + * @param params {object} - Parameters + * @param callback {function} - `function (err, data) {}` + * @returns {void} + */ + reisadvies(params: {}, callback: (err: string, data: {}) => void): void; + + /** + * Prijzen - tariffs + * + * @callback callback + * @param params {object} - Parameters + * @param callback {function} - `function (err, data) {}` + * @returns {void} + */ + prijzen(params: {}, callback: (err: any, data: {}) => void): void; + + /** + * List available stations + * + * @callback callback + * @param [treeKey] {string} - Group by this key + * @param callback {function} - `function (err, data) {}` + */ + stations(treeKey: string, callback: (err: string, data: {}) => void): void; + stations(callback: (err: string, data: {}) => void): void; + + /** + * List disruptions + * + * @callback callback + * @param params {object} - Parameters + * @param callback {function} - `function (err, data) {}` + */ + storingen(params: {}, callback: (err: string, data: {}) => void): void; +} + +declare namespace nsApi { + interface Configuration { + username: string; + password: string; + timeout?: number; + } +} diff --git a/ns-api/ns-api-tests.ts b/ns-api/ns-api-tests.ts new file mode 100644 index 0000000000..8a3b8c5bb6 --- /dev/null +++ b/ns-api/ns-api-tests.ts @@ -0,0 +1,56 @@ +import * as NsApi from "ns-api"; + +let ns: NsApi = NsApi({ + username: "", + password: "", + timeout: 1500 +}); + +ns.vertrektijden("", (err: any, data: Object) => { + if(err) { + console.log(err); + } else { + console.log(data); + } +}); + +// Get travel advise +ns.reisadvies ({}, (err: any, data: Object) => { + if(err) { + console.log(err); + } else { + console.log(data); + } +}); + +ns.prijzen({}, (err: any, data: Object) => { + if(err) { + console.log(err); + } else { + console.log(data); + } +}); + +ns.stations("code", (err: any, data: Object) => { + if(err) { + console.log(err); + } else { + console.log(data); + } +}); + +ns.stations((err: any, data: Object) => { + if(err) { + console.log(err); + } else { + console.log(data); + } +}); + +ns.storingen({}, (err: any, data: Object) => { + if(err) { + console.log(err); + } else { + console.log(data); + } +}); \ No newline at end of file diff --git a/ns-api/tsconfig.json b/ns-api/tsconfig.json new file mode 100644 index 0000000000..fae5845b2d --- /dev/null +++ b/ns-api/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ns-api-tests.ts" + ] +} diff --git a/ns-api/tslint.json b/ns-api/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/ns-api/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }