infogare-api.js
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "infogare-api.js", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"main": "src/core/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -256,4 +256,32 @@ const User = require('./User'); | ||
} | ||
/** | ||
* Get a train from a station | ||
* @param {string} uid The UID of the user | ||
* @param {string} id The station ID | ||
* @param {string} trainId The train ID | ||
* @returns {Train} The train | ||
*/ | ||
async getTrain(uid, id, trainId) { | ||
if (!uid) { | ||
throw new Error('uid is required'); | ||
} | ||
if (!id) { | ||
throw new Error('id is required'); | ||
} | ||
if (!trainId) { | ||
throw new Error('trainId is required'); | ||
} | ||
if (!this.appId) { | ||
throw new Error('appId is required'); | ||
} | ||
const response = await fetch(`${App.apiEndpoint}/user/${uid}/gares/${id}/trains/${trainId}?appId=${this.appId}`); | ||
if (!response.ok) { | ||
throw new StationException(response, 'train ' + trainId); | ||
} | ||
const train = new Train(await response.json()); | ||
return train; | ||
} | ||
} | ||
module.exports = App; |
class Train { | ||
constructor(data) { | ||
this.name = data.name; | ||
this.id = data.id; | ||
@@ -25,6 +24,2 @@ this.alternance = data.alternance; | ||
} | ||
getName() { | ||
return this.name; | ||
} | ||
@@ -31,0 +26,0 @@ getId() { |
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
18542
602
9