-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added middleware and moved notification realtime from account to noti…
…fication
- Loading branch information
Showing
7 changed files
with
116 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
const request = require('../comum/tago_request.js'); | ||
const config = require('../config.js'); | ||
const default_headers = require('../comum/default_headers.js'); | ||
|
||
class Middlewares { | ||
constructor(acc_token) { | ||
this.token = acc_token; | ||
this.default_options = { | ||
'json': true, | ||
'headers': default_headers(this) | ||
}; | ||
} | ||
|
||
/** | ||
* Return list of all middlewares available for tokens | ||
* @param {Boolean} owner if true, get a list of middlewares and tokens owned by the account | ||
* @return {Promise} | ||
*/ | ||
list(owner) { | ||
let url = `${config.api_url}/middleware`; | ||
if (owner) url = `${url}?owner=true`; | ||
const method = 'GET'; | ||
|
||
const options = Object.assign({}, this.default_options, {url, method}); | ||
return request(options); | ||
} | ||
|
||
/** | ||
* Remove older token and returns a new token for the middleware. | ||
* @param {String} middleware_name name of the middleware | ||
* @return {Promise} | ||
*/ | ||
genToken(middleware_name) { | ||
const url = `${config.api_url}/middleware/gen_token/${middleware_name}`; | ||
const method = 'PUT'; | ||
|
||
const options = Object.assign({}, this.default_options, {url, method}); | ||
return request(options); | ||
} | ||
} | ||
|
||
module.exports = Middlewares; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,39 @@ | ||
'use strict'; | ||
const services = { | ||
weather: require('./weather'), | ||
currency: require('./currency'), | ||
geocoding: require('./geocoding'), | ||
distance: require('./distance') | ||
}; | ||
const request = require('../comum/tago_request.js'); | ||
const config = require('../config.js'); | ||
const default_headers = require('../comum/default_headers.js'); | ||
|
||
class Extra { | ||
constructor(service, api_key) { | ||
if (!service) { throw 'Missing parameter service'; } | ||
else if (!api_key) { throw 'Missing parameter api_key'; } | ||
/** Class for the device and data */ | ||
class Middleware { | ||
/** Device | ||
* @param {String} Middleware Token | ||
* @return {Object} Middleware Object | ||
*/ | ||
constructor(token, details) { | ||
this.token = token; | ||
this.default_options = { | ||
'json': true, | ||
'headers': default_headers(this) | ||
}; | ||
|
||
if (!services[service]) { | ||
throw `Can\'t find service ${service}`; | ||
if (details) { | ||
this.default_options.qs = {'details': true}; | ||
} | ||
} | ||
|
||
/** | ||
* Get token of the device by its serial number. | ||
* Return nothing if the serie number is not associeted with middleware | ||
* @param {STRING} serial_number serial number of the device | ||
* @return {Promise} | ||
*/ | ||
getBySerieNum(serial_number) { | ||
let url = `${config.api_url}/middleware/get_by_serienum/${serial_number}`; | ||
let method = 'GET'; | ||
|
||
return new services[service](api_key); | ||
let options = Object.assign({}, this.default_options, {url, method}); | ||
return request(options); | ||
} | ||
} | ||
|
||
module.exports = Extra; | ||
module.exports = Middleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
'use strict'; | ||
exports.Account = require('./account/'); | ||
exports.Analysis = require('./analysis/'); | ||
exports.Device = require('./device/'); | ||
exports.Services = require('./services/'); | ||
exports.Utils = require('./utils/'); | ||
exports.Account = require('./account/'); | ||
exports.Analysis = require('./analysis/'); | ||
exports.Device = require('./device/'); | ||
exports.Middleware = require('./middleware/'); | ||
exports.Services = require('./services/'); | ||
exports.Utils = require('./utils/'); |
Empty file.