poe-api-manager
Version:
poe.ninja and poe.watch API
47 lines (46 loc) • 1.77 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.watch/func/getData"));
/**
* Represents an abstract class for interacting with the PoeWatch API.
* @abstract
* @class
* @implements {IPoeWatch}
*/
class PoeWatch {
league;
type;
/**
* Creates a new instance of PoeWatch.
* @param {string} league - The league name to get data from.
* @param {string} type - The type of data to retrieve (e.g. 'currency', 'items', etc.).
*/
constructor(league, type) {
this.league = league;
this.type = type;
}
/**
* Retrieves data from the PoeWatch API.
* @param {string[]} requestedProperties Optional array of properties to include in the response.
* @returns {Promise<object[]>} A promise that resolves to an array of objects containing the requested data.
* @throws {Error} If there is an error retrieving the data.
*/
async getData(requestedProperties) {
try {
return (0, getData_1.default)(this.league, this.type, requestedProperties);
}
catch (error) {
// Pass through custom errors
if (error instanceof CustomError_1.default) {
throw error;
}
throw new ApiError_1.default(`Error retrieving ${this.type} data: ${error.message}`, 500, { league: this.league, type: this.type });
}
}
}
exports.default = PoeWatch;