brawlhalla-api-ts
Version:
TypeScript wrapper for the Brawlhalla API.
38 lines • 1.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var axios_1 = require("axios");
var BrawlhallaRequest = (function () {
function BrawlhallaRequest(apiKey, apiUrl) {
this.apiUrl = 'https://api.brawlhalla.com';
this.apiKey = apiKey;
this.apiUrl = apiUrl;
}
BrawlhallaRequest.prototype.doRequest = function (pathArguments, params) {
var _this = this;
var requestParameters = params !== undefined ? { params: params } : { params: {} };
requestParameters.params.api_key = this.apiKey;
return axios_1.default.get(this.apiUrl + "/" + pathArguments.join('/'), requestParameters)
.then(function (response) {
return Promise.resolve(_this.parseUtf8Recursive(response.data));
});
};
BrawlhallaRequest.prototype.parseUtf8Recursive = function (objectToConvert) {
var _this = this;
Object.keys(objectToConvert).forEach(function (key) {
if (typeof objectToConvert[key] === 'object') {
objectToConvert[key] = _this.parseUtf8Recursive(objectToConvert[key]);
}
else if (typeof objectToConvert[key] === 'string') {
try {
objectToConvert[key] = decodeURIComponent(escape(objectToConvert[key]));
}
catch (_a) {
}
}
});
return objectToConvert;
};
return BrawlhallaRequest;
}());
exports.BrawlhallaRequest = BrawlhallaRequest;
//# sourceMappingURL=BrawlhallaRequest.js.map