pointercrate
Version:
Unofficial Pointercrate API wrapper written in TypeScript
134 lines (133 loc) • 5.98 kB
JavaScript
const BasePointercrate = require("./BasePointercrate");
const Endpoints = require("./Endpoints");
/**
* The flagship class of the library. Contains function wrappers for API endpoints.
*/
class Pointercrate extends BasePointercrate {
/**
* Registers a new pointercrate account.
* @param options Options to send as a JSON to the Pointercrate API.
* @returns A user object representing your newly registered account.
*/
async createAccount(options) {
if (typeof options != "object")
throw new TypeError("Parameter options is not an object");
return this.sendRequest(Endpoints.registerAuth(), { method: "POST", body: options });
}
/**
* Retrieves a, potentially filtered, list of every demon in the Pointercrate database, sorted by `id`.
* @param options Options to send as query parameters to the Pointercrate API.
* @returns A list of demons.
*/
async getDemons(options = {}) {
return this.sendRequest(Endpoints.demons(), { body: options });
}
/**
* Retrieves a, potentially filtered, list of only the demons currently placed on the demonlist, sorted by `position`.
* @param options Options to send as query parameters to the Pointercrate API.
* @returns A list of demons.
*/
async getListedDemons(options = {}) {
return this.sendRequest(Endpoints.listedDemons(), { body: options });
}
/**
* Retrieves detailed information about the demon with the given `id`.
* @param id A numeric id that represents a demon.
* @param headers Headers to send to the Pointercrate API.
* @returns The requested demon object.
*/
async getDemon(id, headers = {}) {
if (isNaN(Number(id)))
throw new TypeError("Parameter id is not a number");
return this.sendRequest(Endpoints.demons(id), { headers });
}
/**
* Allows to retrieve a potentially filtered list of all players having records on the list, or are associated with a demon in some other way.
* @param options Options to send as query parameters to the Pointercrate API.
* @param headers Headers to send to the Pointercrate API.
* @returns A list of players.
*/
async getPlayers(options = {}, headers = {}) {
return this.sendRequest(Endpoints.players(), { body: options, headers });
}
/**
* This is a more limited (and slower) version of `Pointercrate#getPlayers`. It should only be used if the additional information (player scores and ranking) is actually required.
* @param options Options to send as query parameters to the Pointercrate API.
* @returns A list of players.
*/
async getPlayerRanking(options = {}) {
return this.sendRequest(Endpoints.playerRanking(), { body: options });
}
/**
* Retrieves detailed information about the player with the given `id`.
* @param id A numeric id that represents a player.
* @param headers Headers to send to the Pointercrate API.
* @returns The requested player object.
*/
async getPlayer(id, headers = {}) {
if (isNaN(Number(id)))
throw new TypeError("Parameter id is not a number");
if (id < 0)
id = -id;
return this.sendRequest(Endpoints.players(id), { headers });
}
/**
* Allows to retrieve a list of records.
* @param options Options to send as query parameters to the Pointercrate API.
* @param headers Headers to send to the Pointercrate API.
* @returns A list of records.
*/
async getRecords(options = {}, headers = {}) {
return this.sendRequest(Endpoints.records(), { body: options, headers });
}
/**
* Either adds a record directly to the list, or submits a record to the list mods for approval. The record must meet the demons requirement, and the holder in question needn't be banned.
* @param options Options to send as a JSON to the Pointercrate API.
* @param headers Headers to send to the Pointercrate API.
* @returns The newly created record object.
*/
async postRecord(options, headers = {}) {
if (typeof options != "object")
throw new TypeError("Parameter options is not an object");
return this.sendRequest(Endpoints.records(), { method: "POST", body: options, headers });
}
/**
* Retrieves detailed information about the record with the given `id`.
* @param id A numeric id that represents a record.
* @param headers Headers to send to the Pointercrate API.
* @returns The requested record object.
*/
async getRecord(id, headers = {}) {
if (isNaN(Number(id)))
throw new TypeError("Parameter id is not a number");
if (id < 0)
id = -id;
return this.sendRequest(Endpoints.records(id), { headers });
}
/**
* @param code A two-letter country code that represents a nation.
*/
async getNationality(code) {
if (typeof code != "string")
throw new TypeError("Parameter code is not a string");
return this.sendRequest(Endpoints.nationalities(code));
}
/**
* @param options Options to send as query parameters to the Pointercrate API.
*/
async getNationalityRanking(options = {}) {
return this.sendRequest(Endpoints.nationalityRanking(), { body: options });
}
/**
* @param code A two-letter country code that represents a nation.
*/
async getNationalitySubdivisions(code) {
if (typeof code != "string")
throw new TypeError("Parameter code is not a string");
return this.sendRequest(Endpoints.nationalitySubdivisions(code));
}
async getListMetadata() {
return this.sendRequest(Endpoints.listInformation());
}
}
module.exports = Pointercrate;