@evolvejs/core
Version:
An advanced Discord API wrapper with TS and JS support
52 lines (51 loc) • 1.48 kB
JavaScript
;
/* eslint-disable no-mixed-spaces-and-tabs */
Object.defineProperty(exports, "__esModule", { value: true });
exports.RestAPI = void 0;
const RestAPIHandler_1 = require("./RestAPIHandler");
const objex_1 = require("@evolvejs/objex");
/**
* RestAPI Class
*
* @param {client} - Your EvolveClient
*/
class RestAPI {
constructor(client) {
Object.defineProperty(this, "_client", {
value: client,
enumerable: false,
writable: false,
configurable: false,
});
Object.defineProperty(this, "_handler", {
value: new objex_1.Objex(),
enumerable: false,
writable: false,
configurable: false,
});
}
/**
*
* @param endpoint
* Gets a Handler for the specific endpoint or creates a new one
*/
endpoint(endpoint) {
if (this._handler.has(endpoint))
return this._handler.get(endpoint);
else {
this._handler.set(endpoint, new RestAPIHandler_1.RestAPIHandler(this._client, endpoint));
return this._handler.get(endpoint);
}
}
get active() {
return this.activeRequests.length !== 0;
}
get activeRequests() {
const activeArray = [];
for (const [_, v] of this._handler.filter((handler) => handler.active === true)) {
activeArray.push(v);
}
return activeArray;
}
}
exports.RestAPI = RestAPI;