emt-bus
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -7,3 +7,4 @@ 'use strict'; | ||
const bike_endpoints = require('./bike_endpoints'); | ||
const parking_endpoints = require('./parking_endpoints'); | ||
module.exports = { bus_endpoints, geo_endpoints, media_endpoints, bike_endpoints }; | ||
module.exports = { bus_endpoints, geo_endpoints, media_endpoints, bike_endpoints, parking_endpoints }; |
@@ -5,4 +5,4 @@ 'use strict'; | ||
exports.BIKE_DOMAIN = 'https://rbdata.emtmadrid.es:8443/BiciMad'; | ||
exports.BIKE_DOMAIN = 'https://rbdata.emtmadrid.es:8443/'; | ||
exports.PARKING_DOMAIN = 'https://servicios.emtmadrid.es:8443/InfoParking/InfoParking.svc'; |
131
index.js
@@ -19,3 +19,4 @@ 'use strict'; | ||
media_endpoints, | ||
bike_endpoints | ||
bike_endpoints, | ||
parking_endpoints | ||
} = require('./config/endpoints'); | ||
@@ -36,3 +37,3 @@ | ||
if (service === 'bike') return new Bike(clientId, passKey, BIKE, 'GET'); | ||
if (service === 'parking') return; | ||
if (service === 'parking') return new Park(clientId, passKey, 'POST'); | ||
}; | ||
@@ -47,4 +48,4 @@ }; | ||
const Service = function (clientId, passKey, rest_method) { | ||
var client = clientId; // private attribute | ||
var pass = passKey; // private attribute | ||
let client = clientId; // private attribute | ||
let pass = passKey; // private attribute | ||
this.rest_method = rest_method; | ||
@@ -74,5 +75,3 @@ | ||
this.glueURL = function (endpoint, params) { | ||
if (this.category !== BIKE) return `${BUS_DOMAIN}${this.category}/${endpoint}.php`; | ||
return `${BIKE_DOMAIN}/${endpoint}/${this.getClient()}/${this.getPassword()}}`; | ||
return `${BUS_DOMAIN}${this.category}/${endpoint}.php`; | ||
}; | ||
@@ -115,5 +114,5 @@ /** | ||
}) | ||
.then(response => { | ||
return JSON.parse(response); | ||
}); | ||
.then(response => { | ||
return JSON.parse(response); | ||
}); | ||
}; | ||
@@ -323,3 +322,3 @@ | ||
*/ | ||
Multimedia.prototype.GetStreetRoute = function (params) { | ||
Multimedia.prototype.getStreetRoute = function (params) { | ||
return this.makeRequest(media_endpoints.GET_STREET_ROUTE, params); | ||
@@ -363,2 +362,7 @@ }; | ||
this.category = category; | ||
this.glueURL = function (endpoint, params) { | ||
if (isNaN(params)) params = ''; | ||
return `${BIKE_DOMAIN}/${this.category}/${endpoint}/${this.getClient()}/${this.getPassword()}}/${params}`; | ||
}; | ||
}; | ||
@@ -376,3 +380,3 @@ | ||
/** | ||
* Obtiene la información de una base. | ||
* Obtiene la información de una base | ||
*/ | ||
@@ -383,12 +387,93 @@ Bike.prototype.getSingleStations = function (baseId) { | ||
// 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' | ||
}; | ||
/** | ||
* Set of services that let's know the actual state and availability | ||
* for all the bikes located in Madrid | ||
* | ||
* @param {string} clientId - client username to identify with | ||
* @param {string} passKey - password to validate the client autentification | ||
*/ | ||
const Park = function (clientId, passKey, rest_method) { | ||
Service.call(this, clientId, passKey, rest_method); | ||
this.glueURL = function (endpoint, params) { | ||
let newURL = `${PARKING_DOMAIN}/${endpoint}/${this.getClient()},${this.getPassword()}`; | ||
for(param in params) { | ||
newURL += `,${param}`; | ||
} | ||
return newURL; | ||
}; | ||
} | ||
Park.prototype = Object.create(Service.prototype); // inherits from service class | ||
/** | ||
* Obtiene la información detallada de un aparcamiento concreto: Información sobre sus | ||
* accesos, horarios, tarifas, servicios que ofrece y cifras de ocupación. | ||
*/ | ||
Park.prototype.detailParking = function () { | ||
return this.makeRequest(parking_endpoints.DETAIL_PARKING); | ||
} | ||
/** | ||
* Obtiene la información detallada de un POI concreto (o de todos ellos), con id, código de | ||
* familia, nombre estándar, nombre traducido, descripción, web, horario, servicios de pago, | ||
* así como sus imágenes asociadas con nombre, ruta y descripción. | ||
*/ | ||
Park.prototype.detailPOI = function () { | ||
return this.makeRequest(parking_endpoints.DETAIL_POI); | ||
} | ||
/** | ||
* Obtiene una lista de todos los elementos (características de aparcamientos, categorías de | ||
* POIs,…) que tienen un icono asociado, con nombre, descripción si se dispone de ella, grupo al | ||
* que pertenece y ruta del icono que la representa. | ||
*/ | ||
Park.prototype.iconDescription = function () { | ||
return this.makeRequest(parking_endpoints.ICON_DESCRIPTION); | ||
} | ||
/** | ||
* Obtiene información genérica de POIs y aparcamientos, independiente del idioma (dirección, | ||
* coordenadas, códigos de familia, tipo y categoría,…). | ||
*/ | ||
Park.prototype.infoParkingPoi = function () { | ||
return this.makeRequest(parking_endpoints.INFO_PARKING_POI); | ||
} | ||
/** | ||
* Obtiene una lista de las características activas de los aparcamientos, con nombre, código y | ||
* grupo de la característica, descripción si se dispone de ella y ruta del icono que la representa. | ||
*/ | ||
Park.prototype.listFeatures = function () { | ||
return this.makeRequest(parking_endpoints.LIST_FEATURES); | ||
} | ||
/** | ||
* Obtiene una lista de todos los aparcamientos activos, con su id, familia, nombre, categoría, | ||
* tipo, dirección completa y coordenadas. | ||
* @param {*} language | ||
*/ | ||
Park.prototype.listParking = function (language) { | ||
const body = { language }; | ||
return this.makeRequest(parking_endpoints.LIST_PARKING, body); | ||
} | ||
/** | ||
* Obtiene una lista de direcciones y POIs (aparcamientos incluidos) que coincidan total o | ||
* parcialmente, con un texto pasado como parámetro. | ||
* @param {*} address | ||
* @param {*} language | ||
*/ | ||
Park.prototype.listStreetPoisParking = function (address, language) { | ||
const body = { address, language }; | ||
return this.makeRequest(parking_endpoints.LIST_STREET_POIS_PARKING, address, body); | ||
} | ||
/** | ||
* Obtiene una lista de las familias, tipos y categorías de POIs activos en el sistema. | ||
* @param {*} language | ||
*/ | ||
Park.prototype.listTypesPOIs = function (language) { | ||
const body = { language }; | ||
return this.makeRequest(parking_endpoints.LIST_TYPES_POIS, body); | ||
} |
{ | ||
"name": "emt-bus", | ||
"version": "1.0.2", | ||
"description": "Library that works a layer over the emtmadrid bus service API", | ||
"version": "1.0.3", | ||
"description": "Library that works a layer over the emt API service", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -1,2 +0,2 @@ | ||
# EMT-bus | ||
# EMT-library | ||
<a href="https://snyk.io/test/github/lorengamboa/emt-bus"> | ||
@@ -46,3 +46,3 @@ <img src="https://snyk.io/test/github/lorengamboa/emt-bus/badge.svg"></a> | ||
### Bus Methods 🚌 | ||
### 🚌 Bus Methods | ||
@@ -59,3 +59,3 @@ | Methods|Description | | ||
### Geo Methods 🌍 | ||
### 🌍 Geo Methods | ||
@@ -76,6 +76,31 @@ | Methods|Description | | ||
### Media Methods 📺 | ||
### 📺 Media Methods | ||
### Bike Methods 🚲 | ||
| Methods|Description | | ||
| ---------|-------------| | ||
| getEstimatesIncident| Get estimate arrival time to stop and its related issues | ||
| getStreetRoute|Request up to three optimal routes from one place to another using bus or walking, source and destination must be in a format known for the system, which means that should have been validated by a GetStreet call | ||
| getRouteWithAlarm| | | ||
| getRouteWithAlarmResponse| | | ||
| getRoute| | | ||
| getRouteResponse| | | ||
### Parking Methods 🅿 | ||
### 🚲 Bike Methods | ||
| Methods|Description | | ||
| ---------|-------------| | ||
| getStations|Obtiene la relación de todas las bases de Bicimad y su estado operacional. | | ||
| getSingleStations|Obtiene la información de una base | | ||
### 🅿 Parking Methods | ||
| Methods|Description | | ||
| ---------|-------------| | ||
| detailParking|N/A | | ||
| detailPOI|N/A | | ||
| iconDescription|N/A| | ||
| infoParkingPoi|N/A| | ||
| listFeatures|N/A| | ||
| listParking|N/A| | ||
| listStreetPoisParking|N/A| | ||
| listTypesPOIs|N/A| |
@@ -21,3 +21,3 @@ 'use strict'; | ||
it('/getCalendar', function () { | ||
return bus.getCalendar('09/09/2016','09/09/2017') | ||
return bus.getCalendar('09/09/2016', '09/09/2017') | ||
.then(function (res) { | ||
@@ -87,9 +87,16 @@ assert.equal(res['resultDescription'], "Resultado de la operacion Correcta"); | ||
it('/getStations', function () { | ||
return bike.getStations('09/09/2016','09/09/2017') | ||
return bike.getStations() | ||
.then(function (res) { | ||
console.log(res); | ||
assert.equal(res["code"], "0"); | ||
}); | ||
}); | ||
it('/getSingleStations', function () { | ||
return bike.getSingleStations("1") | ||
.then(function (res) { | ||
assert.equal(res["code"], "0"); | ||
}); | ||
}); | ||
}); | ||
}); |
25924
16
594
104