gigaaa-botkit-ext
Version:
Gigaaa Platfrom integration with Botkit
90 lines (73 loc) • 2.13 kB
JavaScript
var request = require('request-promise');
var q = require('q');
module.exports = Api;
function Api(config) {
this.config = {
endpoint: 'https://api.gconsole.io/v1/api/v1/',
token: ''
};
if (config) {
this.config = Object.assign(this.config, config);
}
}
Api.prototype.getUser = function(id) {
var opts = {
method: 'GET',
uri: this.config.endpoint + 'users/' + id + '?api_token=' + this.config.token,
json: true,
headers: {
'Authorization': this.config.bearerToken,
'Content-Type': 'application/json'
}
};
return request(opts)
.then(response => response)
.catch(err => console.error("Error: 501 ---> Internal server error!"));
};
Api.prototype.getUserPhones = function(id) {
var opts = {
method: 'GET',
uri: 'https://api.gigaaa.link/api/v1/users/' + id + '/phones',
json: true,
headers: {
'Authorization': 'Bearer ' + this.config.token,
'Content-Type': 'application/json'
}
};
return request(opts)
.then(response => response)
.catch(err => console.error("Error: 501 ---> Internal server error!"));
};
Api.prototype.getUserAddresses = function(id) {
var opts = {
method: 'GET',
uri: 'https://api.gigaaa.link/api/v1/users/' + id + '/addresses',
json: true,
headers: {
'Authorization': 'Bearer ' + this.config.token,
'Content-Type': 'application/json'
}
};
return request(opts)
.then(response => response)
.catch(err => console.error("Error: 501 ---> Internal server error!"));
};
Api.prototype.getLanguage = function(id) {
var opts = {
method: 'GET',
uri: this.config.endpoint + 'languages?api_token=' + this.config.token,
json: true,
headers: {
'Authorization': this.config.bearerToken,
'Content-Type': 'application/json'
}
};
return request(opts)
.then(response => {
if (response.languages.length) {
return response.languages.find(function(l) { return l.id.toString() === id.toString(); });
}
return null;
})
.catch(err => console.error("Error: 501 ---> Internal server error!"));
};