mineplex
Version:
Wrapper for the Mineplex API
65 lines (64 loc) • 2.51 kB
JavaScript
;
var request = require("request");
var Promise = require("bluebird");
var APIError = (function () {
function APIError(base) {
this.name = base["error"];
this.statusCode = base["statusCode"];
this.error = base["error"];
this.message = base["message"] || base["error"];
}
return APIError;
}());
exports.APIError = APIError;
;
var MineplexAPI = (function () {
function MineplexAPI(apiKey, baseUrl) {
this.baseUrl = baseUrl || "https://api.mineplex.com/pc";
this.apiKey = apiKey;
}
MineplexAPI.prototype.getPlayer = function (player, callback) {
return this.apiCall("player/" + player, callback);
};
MineplexAPI.prototype.getPlayerStatus = function (player, callback) {
return this.apiCall("player/" + player + "/status", callback);
};
MineplexAPI.prototype.getPlayerFriends = function (player, callback) {
return this.apiCall("player/" + player + "/friends", callback);
};
MineplexAPI.prototype.getNetworkStatus = function (callback) {
return this.apiCall("network", callback);
};
MineplexAPI.prototype.getRegionStatus = function (region, callback) {
return this.apiCall("network/" + region, callback);
};
MineplexAPI.prototype.getServerStatus = function (region, server, callback) {
return this.apiCall("network/" + region, callback);
};
MineplexAPI.prototype.getAmplifierGroups = function (callback) {
return this.apiCall("amplifierGroup", callback);
};
MineplexAPI.prototype.getAmplifiers = function (group, callback) {
return this.apiCall("amplifier/" + group, callback);
};
MineplexAPI.prototype.getAllAmplifiers = function (callback) {
return this.apiCall("amplifier", callback);
};
MineplexAPI.prototype.apiCall = function (resource, callback) {
var _this = this;
return new Promise(function (resolve, reject) {
request({ url: _this.buildUrl(resource), json: true }, function (err, response, body) {
if (err || response.statusCode !== 200) {
reject(err || new APIError(body));
return;
}
resolve(body);
});
}).asCallback(callback);
};
MineplexAPI.prototype.buildUrl = function (resource) {
return this.baseUrl + "/" + resource + "?apiKey=" + this.apiKey;
};
return MineplexAPI;
}());
exports.MineplexAPI = MineplexAPI;