poe-api-manager
Version:
poe.ninja and poe.watch API
51 lines (50 loc) • 1.88 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ApiError_1 = __importDefault(require("../errors/ApiError"));
const CustomError_1 = __importDefault(require("../errors/CustomError"));
const getData_1 = __importDefault(require("../modules/poe.ninja/func/getData"));
/**
* Abstract class representing a PoeNinja.
* @abstract
* @class
* @implements {IPoeNinja}
*/
class PoeNinja {
league;
typeName;
type;
/**
* Represents a PoeNinja object.
* @constructor
* @param {string} league - The league name.
* @param {string} typeName
* @param {string} type - The type.
*/
constructor(league, typeName, type) {
this.league = league;
this.typeName = typeName;
this.type = type;
}
/**
* Retrieves data from the API based on the specified league, type name, and type.
* @param {string} requestedProperties - Optional array of properties to include in the retrieved data.
* @returns {Promise<object[]>} A promise that resolves to an array of objects containing the retrieved data.
* @throws {Error} If there is an error retrieving the data.
*/
async getData(requestedProperties) {
try {
return (0, getData_1.default)(this.league, this.typeName, this.type, requestedProperties);
}
catch (error) {
// Pass through custom errors
if (error instanceof CustomError_1.default) {
throw error;
}
throw new ApiError_1.default(`Error getData ${this.typeName} and ${this.type} data: ${error.message}`, 500, { league: this.league, typeName: this.typeName, type: this.type });
}
}
}
exports.default = PoeNinja;