Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

infogare-api.js

Package Overview
Dependencies
Maintainers
0
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

infogare-api.js - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

src/modules/Train.js

2

package.json
{
"name": "infogare-api.js",
"version": "1.0.2",
"version": "1.0.3",
"main": "src/core/index.js",

@@ -5,0 +5,0 @@ "scripts": {

const InfoGareApp = require('../modules/App');
const User = require('../modules/User');
const Station = require('../modules/Station');
const Train = require('../modules/Train');
const { UserNotFoundException, StationNotFoundException } = require('../modules/Exceptions');

@@ -10,4 +11,5 @@

Station,
Train,
UserNotFoundException,
StationNotFoundException
};
const User = require('./User');
const Station = require('./Station');
const Train = require('./Train');
const { UserException, StationException } = require('./Exceptions');

@@ -55,6 +56,6 @@

}
if (!this.#appId) {
if (!this.appId) {
throw new Error('appId is required');
}
const response = await fetch(`${App.apiEndpoint}/user/${uid}?appId=${this.#appId}`);
const response = await fetch(`${App.apiEndpoint}/user/${uid}?appId=${this.appId}`);
if (!response.ok) {

@@ -86,6 +87,6 @@ throw new UserException(response, uid);

}
if (!this.#appId) {
if (!this.appId) {
throw new Error('appId is required');
}
const response = await fetch(`${App.apiEndpoint}/user/${uid}/gares/${id}?appId=${this.#appId}`);
const response = await fetch(`${App.apiEndpoint}/user/${uid}/gares/${id}?appId=${this.appId}`);
if (!response.ok) {

@@ -98,2 +99,8 @@ throw new StationException(response, id);

/**
* Get a station by its name
* @param {string} uid The UID of the user
* @param {string} name The station name
* @returns {Station} The station
*/
async getStationByName(uid, name) {

@@ -106,6 +113,6 @@ if (!uid) {

}
if (!this.#appId) {
if (!this.appId) {
throw new Error('appId is required');
}
const response = await fetch(`${App.apiEndpoint}/user/${uid}/gares?appId=${this.#appId}&name=${encodeURIComponent(name)}`);
const response = await fetch(`${App.apiEndpoint}/user/${uid}/gares?appId=${this.appId}&name=${encodeURIComponent(name)}`);
if (!response.ok) {

@@ -118,2 +125,32 @@ throw new StationException(response, name);

/**
* Get all stations from a folder
* @param {string} uid The UID of the user
* @param {string} folder The folder name
* @returns {Station[]} The stations
*/
async getStationsFromFolder(uid, folder) {
if (!uid) {
throw new Error('uid is required');
}
if (!this.appId) {
throw new Error('appId is required');
}
const response = await fetch(`${App.apiEndpoint}/user/${uid}/gares?appId=${this.appId}&folder=${encodeURIComponent(folder)}`);
if (!response.ok) {
throw new StationException(response, 'from folder ' + folder);
}
const stationsJSON = await response.json();
const stations = [];
for (const stationJSON of stationsJSON) {
stations.push(new Station(stationJSON));
}
return stations;
}
/**
* Get all stations
* @param {string} uid The UID of the user
* @returns {Station[]} The stations
*/
async getStations(uid) {

@@ -123,6 +160,6 @@ if (!uid) {

}
if (!this.#appId) {
if (!this.appId) {
throw new Error('appId is required');
}
const response = await fetch(`${App.apiEndpoint}/user/${uid}/gares?appId=${this.#appId}`);
const response = await fetch(`${App.apiEndpoint}/user/${uid}/gares?appId=${this.appId}`);
if (!response.ok) {

@@ -139,2 +176,7 @@ throw new StationException(response, 'all');

/**
* Add a station
* @param {string} uid The UID of the user
* @param {Station} station The station to add
*/
async addStation(uid, station) {

@@ -147,7 +189,7 @@ if (!uid) {

}
if (!this.#appId) {
if (!this.appId) {
throw new Error('appId is required');
}
console.log(JSON.stringify(station));
const response = await fetch(`${App.apiEndpoint}/user/${uid}/gares?appId=${this.#appId}`, {
const response = await fetch(`${App.apiEndpoint}/user/${uid}/gares?appId=${this.appId}`, {
method: 'PUT',

@@ -164,2 +206,8 @@ body: JSON.stringify(station),

/**
* Edit a station
* @param {string} uid The UID of the user
* @param {string} id The station ID
* @param {Station} station The station to edit
*/
async editStation(uid, id, station) {

@@ -175,6 +223,6 @@ if (!uid) {

}
if (!this.#appId) {
if (!this.appId) {
throw new Error('appId is required');
}
const response = await fetch(`${App.apiEndpoint}/user/${uid}/gares/${id}?appId=${this.#appId}`, {
const response = await fetch(`${App.apiEndpoint}/user/${uid}/gares/${id}?appId=${this.appId}`, {
method: 'PATCH',

@@ -190,4 +238,32 @@ body: JSON.stringify(station),

}
/**
* Get trains from a station
* @param {string} uid The UID of the user
* @param {string} id The station ID
* @returns {Train[]} The trains
*/
async getTrains(uid, id) {
if (!uid) {
throw new Error('uid is required');
}
if (!id) {
throw new Error('id is required');
}
if (!this.appId) {
throw new Error('appId is required');
}
const response = await fetch(`${App.apiEndpoint}/user/${uid}/gares/${id}/trains?appId=${this.appId}`);
if (!response.ok) {
throw new StationException(response, 'trains');
}
const trainsJSON = await response.json();
const trains = [];
for (const trainJSON of trainsJSON) {
trains.push(new Train(trainJSON));
}
return trains;
}
}
module.exports = App;

@@ -1,3 +0,6 @@

class User {
const App = require("./App");
const Station = require("./Station");
class User extends App {
#username;

@@ -4,0 +7,0 @@ #email;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc