Socket
Socket
Sign inDemoInstall

emt-bus

Package Overview
Dependencies
53
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

.eslintrc.js

3

config/category/index.js

@@ -7,1 +7,4 @@ 'use strict';

exports.MULTIMEDIA = 'media';

3

config/endpoints/index.js

@@ -5,3 +5,4 @@ 'use strict';

const geo_endpoints = require('./geo_endpoints');
const media_endpoints = require('./media_endpoints');
module.exports = { bus_endpoints, geo_endpoints };
module.exports = { bus_endpoints, geo_endpoints, media_endpoints };

@@ -1,1 +0,7 @@

module.exports = 'https://openbus.emtmadrid.es:9443/emt-proxy-server/last/';
'use strict';
exports.BUS_DOMAIN = 'https://openbus.emtmadrid.es:9443/emt-proxy-server/last/';
exports.BIKE_DOMAIN = 'https://rbdata.emtmadrid.es:8443/BiciMad';
exports.PARKING_DOMAIN = 'https://servicios.emtmadrid.es:8443/InfoParking/InfoParking.svc';
'use strict';
const util = require('util');
const request = require('request-promise');
const SERVER_URL = require('./config/url');
const { BUS, GEO } = require('./config/category');
const { bus_endpoints, geo_endpoints } = require('./config/endpoints');
const {
BUS_DOMAIN,
BIKE_DOMAIN,
PARKING_DOMAIN
} = require('./config/url');
const {
BUS,
GEO,
MULTIMEDIA
} = require('./config/category');
const {
bus_endpoints,
geo_endpoints,
media_endpoints
} = require('./config/endpoints');

@@ -12,3 +23,3 @@ /**

* return a preselected category
* @param {string} clientId - client username to identify with
* @param {string} clientId - Client username to identify with
* @param {string} passKey - Password to validate the client autentification

@@ -18,11 +29,14 @@ * @param {string} category - It can either be bus or geo

module.exports = function emtService(clientId, passKey) {
return function (category) {
if (category === "bus") return new Bus(clientId, passKey, BUS);
if (category === "geo") return new Geo(clientId, passKey, GEO);
}
}
return function typeService(category) {
if (category === 'bus') return new Bus(clientId, passKey, BUS);
if (category === 'geo') return new Geo(clientId, passKey, GEO);
if (category === 'media') return new Geo(clientId, passKey, MULTIMEDIA);
if (category === 'bike') return;
if (category === 'parking') return;
};
};
/**
* Superclass Service that holds the common features across the different service requests
* @param {string} clientId - client username to identify with
* @param {string} clientId - Client username to identify with
* @param {string} passKey - Password to validate the client autentification

@@ -32,54 +46,72 @@ * @param {string} category - It can either be bus or geo

const Service = function (clientId, passKey, category) {
var client = clientId; // private attribute
var pass = passKey; // private attribute
this.category = category;
var client = clientId; // private attribute
var pass = passKey; // private attribute
this.category = category;
this.getClient = function () {
return client;
}
/**
* Getters & Setters
*/
this.getClient = function () {
return client;
};
this.getPassword = function () {
return pass;
}
this.setClient = function (client) {
this.client = client;
};
this.glueURL = function () {
return SERVER_URL + this.category;
}
this.getPassword = function () {
return pass;
};
this.glueAuth = function () {
const auth = {};
auth['idClient'] = this.getClient();
auth['passKey'] = this.getPassword();
this.setPassword = function (pass) {
this.pass = pass;
};
/**
* Forms the entire domain for the desired request
*/
this.glueURL = function () {
return BUS_DOMAIN + this.category;
};
/**
* Forms the authentication credentials so it can be added to
* the body of the request and so, the user can succesfully
* have permission to it.
*/
this.glueAuth = function () {
const auth = {};
auth['idClient'] = this.getClient();
auth['passKey'] = this.getPassword();
return auth;
}
return auth;
};
}
};
/**
* Handles the request as it glues up all the parts needed to
* fit the body
* @param {string} endpoint The Web service endpoint
* @param {object} body The data that will be sent to the ws
* @returns {promise}
*/
Service.prototype.makeRequest = function (endpoint, body = {}) {
/*
Creates an object that will take all the <key, values>
taken from the body after iterating it and end up
embeding the cliendId and the password into it
/*
Creates an object that will embed
the cliendId and the password into
itself
*/
for (var property in body) {
if (body.hasOwnProperty(property)) {
body.property = body.property;
}
}
Object.assign(body, this.glueAuth());
Object.assign(body, this.glueAuth());
return request({
'method': 'POST',
'uri': this.glueURL() + '/' + endpoint + '.php',
'form': body,
'gzip': true,
'strictSSL': false // Spain goverment sign their own SSL certificates, ಠ.ಠ
})
.then(function (response) {
return JSON.parse(response);
});
};
return request({
'method': 'POST',
'uri': this.glueURL() + '/' + endpoint + '.php',
'form': body,
'gzip': true,
'strictSSL': false // Spain's goverment signs their own SSL certificates, ಠ.ಠ
})
.then(function (response) {
return JSON.parse(response);
});
}
/**

@@ -94,4 +126,4 @@ * Bus service that holds all it's methods to make accesible request and return a response

const Bus = function (clientId, passKey, category) {
Service.call(this, clientId, passKey, category);
}
Service.call(this, clientId, passKey, category);
};

@@ -102,17 +134,26 @@ Bus.prototype = Object.create(Service.prototype); // inherits from service class

* Get EMT Calendar for all days and line schedules for a range of dates
* @param {string} SelectDateBegin
* @param {string} SelectDateEnd
* @returns {promise}
*/
Bus.prototype.getCalendar = function (params) {
return this.makeRequest(bus_endpoints.GET_CALENDAR, params);
Bus.prototype.getCalendar = function (SelectDateBegin,SelectDateEnd) {
const body = {SelectDateBegin, SelectDateEnd}
return this.makeRequest(bus_endpoints.GET_CALENDAR, body);
};
/**
* Returns every line type and their details
* @returns {promise}
*/
Bus.prototype.getGroups = function () {
return this.makeRequest(bus_endpoints.GET_GROUPS);
return this.makeRequest(bus_endpoints.GET_GROUPS);
};
/**
* Returns lines with description and group
* @param {string} SelectDate
* @param {string} Lines
* @returns {promise}
*/
Bus.prototype.getListLines = function (params) {
return this.makeRequest(bus_endpoints.GET_LIST_LINES, params);
Bus.prototype.getListLines = function (SelectDate, Lines) {
const body = {SelectDate, Lines}
return this.makeRequest(bus_endpoints.GET_LIST_LINES, body);
};

@@ -122,5 +163,8 @@ /**

* lines and directions
* @param {string} Nodes
* @returns {promise}
*/
Bus.prototype.getNodesLines = function (params) {
return this.makeRequest(bus_endpoints.GET_NODES_LINES, params);
Bus.prototype.getNodesLines = function (Nodes) {
const body = {Nodes};
return this.makeRequest(bus_endpoints.GET_NODES_LINES, body);
};

@@ -130,23 +174,39 @@ /**

* coordinates for stops and axes
* @param {string} SelectDate
* @param {string} Lines
* @returns {promise}
*/
Bus.prototype.getRouteLines = function (params) {
return this.makeRequest(bus_endpoints.GET_ROUTE_LINES, params);
Bus.prototype.getRouteLines = function (SelectDate, Lines) {
const body = {SelectDate, Lines};
return this.makeRequest(bus_endpoints.GET_ROUTE_LINES, body);
};
/**
* Get line route with vertex info to build map and coordinates for Stops
* @param {string} SelectDate
* @param {string} Lines
* @returns {promise}
*/
Bus.prototype.getRouteLinesRoute = function (params) {
return this.makeRequest(bus_endpoints.GET_ROUTE_LINES_ROUTE, params);
Bus.prototype.getRouteLinesRoute = function (SelectDate, Lines) {
const body = {SelectDate, Lines}
return this.makeRequest(bus_endpoints.GET_ROUTE_LINES_ROUTE, body);
};
/**
* Provices information about the requested line at travel details
* @param {string} SelectDate
* @param {string} Lines
* @returns {promise}
*/
Bus.prototype.getTimeTableLines = function (params) {
return this.makeRequest(bus_endpoints.GET_TIME_TABLE_LINES, params);
Bus.prototype.getTimeTableLines = function (SelectDate, Lines) {
const body = {SelectDate, Lines}
return this.makeRequest(bus_endpoints.GET_TIME_TABLE_LINES, body);
};
/**
* Returns current schedules for the requested lines
* @param {string} SelectDate
* @param {string} Lines
* @returns {promise}
*/
Bus.prototype.getTimesLines = function (params) {
return this.makeRequest(bus_endpoints.GET_TIMES_LINES, params);
Bus.prototype.getTimesLines = function (SelectDate, Lines) {
const body = {SelectDate, Lines}
return this.makeRequest(bus_endpoints.GET_TIMES_LINES, body);
};

@@ -163,4 +223,4 @@

const Geo = function (clientId, passKey, category) {
Service.call(this, clientId, passKey, category);
}
Service.call(this, clientId, passKey, category);
};

@@ -172,4 +232,4 @@ Geo.prototype = Object.create(Service.prototype); // inherits from service class

*/
Geo.prototype.getArriveStop = function () {
return this.makeRequest(geo_endpoints.GET_ARRIVE_STOP, params);
Geo.prototype.getArriveStop = function (params) {
return this.makeRequest(geo_endpoints.GET_ARRIVE_STOP, params);
};

@@ -179,4 +239,4 @@ /**

*/
Geo.prototype.getGroups = function () {
return this.makeRequest(geo_endpoints.GET_GROUPS, params);
Geo.prototype.getGroups = function (params) {
return this.makeRequest(geo_endpoints.GET_GROUPS, params);
};

@@ -186,4 +246,4 @@ /**

*/
Geo.prototype.getInfoLine = function () {
return this.makeRequest(geo_endpoints.GET_INFO_LINE, params);
Geo.prototype.getInfoLine = function (params) {
return this.makeRequest(geo_endpoints.GET_INFO_LINE, params);
};

@@ -193,4 +253,4 @@ /**

*/
Geo.prototype.getInfoLineExtend = function () {
return this.makeRequest(geo_endpoints.GET_INFO_LINE_EXTEND, params);
Geo.prototype.getInfoLineExtend = function (params) {
return this.makeRequest(geo_endpoints.GET_INFO_LINE_EXTEND, params);
};

@@ -200,4 +260,4 @@ /**

*/
Geo.prototype.getPointsOfInterest = function () {
return this.makeRequest(geo_endpoints.GET_POINTS_OF_INTEREST, params);
Geo.prototype.getPointsOfInterest = function (params) {
return this.makeRequest(geo_endpoints.GET_POINTS_OF_INTEREST, params);
};

@@ -207,4 +267,4 @@ /**

*/
Geo.prototype.getPointsOfInterestTypes = function () {
return this.makeRequest(geo_endpoints.GET_POINTS_OF_INTEREST_TYPES, params);
Geo.prototype.getPointsOfInterestTypes = function (params) {
return this.makeRequest(geo_endpoints.GET_POINTS_OF_INTEREST_TYPES, params);
};

@@ -214,4 +274,4 @@ /**

*/
Geo.prototype.getStopsFromStop = function () {
return this.makeRequest(geo_endpoints.GET_STOPS_FROM_STOP, params);
Geo.prototype.getStopsFromStop = function (params) {
return this.makeRequest(geo_endpoints.GET_STOPS_FROM_STOP, params);
};

@@ -221,10 +281,10 @@ /**

*/
Geo.prototype.getStopsFromXY = function () {
return this.makeRequest(geo_endpoints.GET_STOPS_FROM_XY, params);
Geo.prototype.getStopsFromXY = function (params) {
return this.makeRequest(geo_endpoints.GET_STOPS_FROM_XY, params);
};
/**
* Provices information about the requested line at travel details
* Provices information about the requested line at travel time
*/
Geo.prototype.getStopsLine = function () {
return this.makeRequest(geo_endpoints.GET_STOPS_LINE, params);
Geo.prototype.getStopsLine = function (params) {
return this.makeRequest(geo_endpoints.GET_STOPS_LINE, params);
};

@@ -235,4 +295,4 @@ /**

*/
Geo.prototype.getStreet = function () {
return this.makeRequest(geo_endpoints.GET_STREET, params);
Geo.prototype.getStreet = function (params) {
return this.makeRequest(geo_endpoints.GET_STREET, params);
};

@@ -242,4 +302,53 @@ /**

*/
Geo.prototype.getStreetFromXY = function () {
return this.makeRequest(geo_endpoints.GET_STREET_FROM_XY, params);
Geo.prototype.getStreetFromXY = function (params) {
return this.makeRequest(geo_endpoints.GET_STREET_FROM_XY, params);
};
/**
* Multimedia service that holds all it's methods to make accesible request and return a response
* in JSON
* @param {string} clientId - client username to identify with
* @param {string} passKey - password to validate the client autentification
* @param {string} category - It can either be bus or geo
*/
const Multimedia = function (clientId, passKey, category) {
Service.call(this, clientId, passKey, category);
};
Multimedia.prototype = Object.create(Service.prototype); // inherits from service class
Multimedia.prototype.getEstimatesIncident = function (params) {
return this.makeRequest(media_endpoints.getEstimatesIncident, params);
};
Multimedia.prototype.getEstimatesIncident = function (params) {
return this.makeRequest(media_endpoints.GET_ESTIMATES_INCIDENT, params);
};
Multimedia.prototype.getRouteWithAlarm = function (params) {
return this.makeRequest(media_endpoints.GET_ROUTE_WITH_ALARM, params);
};
Multimedia.prototype.getRouteWithAlarmResponse = function (params) {
return this.makeRequest(media_endpoints.GET_ROUTE_WITH_ALARM_RESPONSE, params);
};
Multimedia.prototype.getRoute = function (params) {
return this.makeRequest(media_endpoints.GET_ROUTE, params);
};
Multimedia.prototype.getRouteResponse = function (params) {
return this.makeRequest(media_endpoints.GET_ROUTE_RESPONSE, params);
};
// Posible ws code responses
const responses = {
0: 'PassKey OK and authorized for period',
1: 'No PassKey necesary',
2: 'PassKey distinct than the current Passkey',
3: 'PassKey expired',
4: 'Client unauthorized',
5: 'Client deactivate',
6: 'Client locked',
9: 'Attemp to Auth Failed'
};
{
"name": "emt-bus",
"version": "1.0.0",
"version": "1.0.1",
"description": "Library that works a layer over the emtmadrid bus service API",

@@ -16,9 +16,7 @@ "main": "index.js",

],
"author": "Lorenzo Gamboa",
"author": "lorenzo Gamboa",
"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/Lorengamboa/EMT-bus.git"
},
"devDependencies": {
"eslint": "^4.12.0",
"eslint-config-google": "^0.9.1",
"mocha": "^4.0.1"

@@ -31,2 +29,2 @@ },

}
}
}

@@ -17,7 +17,11 @@ # EMT-bus

- Geo
- Media
- Bike
- Parking
## Requirements
> Node.js >= v6
## How to install
> npm install emt-bus --save
>npm install emt-bus --save

@@ -28,5 +32,4 @@ ## How to use

```javascript
var EMT = require('emt-bus')('<idClient>','<passKey>');
var EMT = require('emt-bus').('<idClient>', '<passKey>');
```
**Select a an API category**

@@ -36,10 +39,10 @@ ```javascript

```
**Finally, make the request by selecting a method that corresponds to its category**
```javascript
bus.getListLines({ Lines: '', SelectDate: '09/09/1993' }).then ..
bus.getListLines({ Lines: '721', SelectDate: '09/09/1993' }).then ..
```
**Response**
<code></code>
<code>
</code>

@@ -72,2 +75,8 @@ ### Bus Methods 🚌

| getStreet|Returns a list of EMT nodes related to a location. All EMT locations are a group of stops within a target radius and the lines related to each stop in the list.|
| getStreetFromXY|Returns a list of stops from a target coordinate.|
| getStreetFromXY|Returns a list of stops from a target coordinate.|
### Media Methods 📺
### Bike Methods 🚲
### Parking Methods 🅿

@@ -20,63 +20,55 @@ 'use strict';

it('/getCalendar ', function (done) {
bus.getCalendar({ SelectDateBegin: '09/09/2016', SelectDateEnd: '09/09/2017' })
it('/getCalendar', function () {
return bus.getCalendar('09/09/2016','09/09/2017')
.then(function (res) {
assert.equal(res['resultDescription'], "Resultado de la operacion Correcta");
done();
});
});
it('/getGroups ', function (done) {
bus.getGroups()
it('/getGroups ', function () {
return bus.getGroups()
.then(function (res) {
assert.equal(res['resultDescription'], "Resultado de la operacion Correcta");
done();
});
});
it('/getListLines ', function (done) {
bus.getListLines({ SelectDate: '09/09/2016', Lines: '121' })
it('/getListLines ', function () {
return bus.getListLines('09/09/2016', '121')
.then(function (res) {
assert.equal(res['resultDescription'], "Resultado de la operacion Correcta");
done();
});
});
it('/getNodesLines ', function (done) {
bus.getNodesLines({ Nodes: '111' })
it('/getNodesLines ', function () {
return bus.getNodesLines('111')
.then(function (res) {
assert.equal(res['resultDescription'], "Resultado de la operacion Correcta");
done();
});
});
it('/getRouteLines ', function (done) {
bus.getRouteLines({ SelectDate: '09/09/2015', Lines: '123' })
it('/getRouteLines', function () {
return bus.getRouteLines('09/09/2017', '121')
.then(function (res) {
assert.equal(res['resultDescription'], "Resultado de la operacion Correcta");
done();
});
});
it('/getRouteLinesRoute ', function (done) {
bus.getRouteLinesRoute({ SelectDate: '09/09/2015', Lines: '123' })
it('/getRouteLinesRoute', function () {
return bus.getRouteLinesRoute('09/09/2015', '123')
.then(function (res) {
assert.equal(res['resultDescription'], "Resultado de la operacion Correcta");
done();
});
});
it('/getTimeTableLines ', function (done) {
bus.getTimeTableLines({ SelectDate: '09/09/2015', Lines: '123' })
it('/getTimeTableLines ', function () {
return bus.getTimeTableLines('09/09/2016', '121')
.then(function (res) {
assert.equal(res['resultDescription'], "Resultado de la operacion Correcta");
done();
});
});
it('/getTimesLines ', function (done) {
bus.getTimesLines({ SelectDate: '09/09/2015', Lines: '123' })
it('/getTimesLines ', function () {
return bus.getTimesLines('09/09/2016', '121')
.then(function (res) {
assert.equal(res['resultDescription'], "Resultado de la operacion Correcta");
done();
});

@@ -87,19 +79,2 @@ });

describe('Geo API method requests', function (done) {
let geo;
before(function () {
geo = EMT('geo');
});
it('/getListLines ', function (done) {
geo.getArriveStop({ SelectDate: '09/09/2016', Lines: '121' })
.then(function (res) {
assert.equal(res['resultDescription'], "Resultado de la operacion Correcta");
done();
});
});
})
});
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc