ensl_gathers/lib/hive/client.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-08-31 14:30:33 +00:00
"use strict";
2016-11-14 15:08:16 +00:00
const path = require("path");
const request = require("request");
const logger = require("winston");
const querystring = require('querystring');
2016-11-15 10:53:54 +00:00
const UserStatisticsWrapper = require("./stats_wrapper");
2016-11-14 15:08:16 +00:00
const config = require(path.join(__dirname, "../../config/config"));
2015-08-31 14:30:33 +00:00
2016-11-15 10:53:54 +00:00
2015-08-31 14:30:33 +00:00
function HiveClient (options) {
if (!(this instanceof HiveClient)) {
return new HiveClient(options);
}
2016-11-15 10:53:54 +00:00
this.baseUrl = config.hive2_url;
2015-08-31 14:30:33 +00:00
}
2015-09-25 21:23:30 +00:00
HiveClient.prototype.getUserStats = function (user, callback) {
2015-08-31 14:30:33 +00:00
if (!user || !user.hive.id) {
return callback(new Error("Invalid user instance supplied"));
}
return request({
2016-11-15 10:53:54 +00:00
url: `${config.hive_url}/api/get/playerData/${user.hive.id}`,
json: true
}, (error, response, body) => {
return callback(error, response, new UserStatisticsWrapper(body));
});
};
HiveClient.prototype.getUserStatsV2 = function (user, callback) {
if (!user || !user.hive.id) {
return callback(new Error("Invalid user instance supplied"));
}
return request({
url: `${config.hive2_url}/api/get/playerData/${user.hive.id}`,
2015-08-31 14:30:33 +00:00
json: true
2016-11-15 10:53:54 +00:00
}, (error, response, body) => {
return callback(error, response, new UserStatisticsWrapper(body));
});
2015-08-31 14:30:33 +00:00
};
module.exports = HiveClient;