pointercrate
Version:
Unofficial Pointercrate API wrapper written in TypeScript
233 lines (232 loc) • 10.7 kB
JavaScript
const BaseAuthPointercrate = require("./BaseAuthPointercrate");
const Endpoints = require("./Endpoints");
/**
* Pointercrate authentication class. Type: JSON Web.
*/
class JWTAuthPointercrate extends BaseAuthPointercrate {
/**
* @param token The authentication token required.
* @param api An optional url string specifing what API to send requests to.
*/
constructor(token, api = "https://pointercrate.com/api") {
super(token, "Bearer", api);
}
/**
* Gets information about the currently logged in account (that is, the account whose access token is sent).
* @param headers Headers to send to the Pointercrate API.
* @returns A user object representing the account you just logged into.
*/
async getAccount(headers = {}) {
return this.sendAuthRequest(Endpoints.meAuth(), { headers });
}
/**
* Allows the retrieval of a list of all pointercrate users (if you are pointercrate staff), or a list of all users that fall under your juristiction as a team leader.
* @param options Options to send as query parameters to the Pointercrate API.
* @returns A list of users.
*/
async getUsers(options = {}) {
return this.sendAuthRequest(Endpoints.users(), { body: options });
}
/**
* Retrieves detailed information about the user with the given `id`.
* @param id A numeric id that represents a user.
* @param headers Headers to send to the Pointercrate API.
* @returns The requested user object.
*/
async getUser(id, headers = {}) {
if (isNaN(Number(id)))
throw new TypeError("Parameter id is not a number");
return this.sendAuthRequest(Endpoints.users(id), { headers });
}
/**
* Modifies a given user.
* @param id A numeric id that represents a user.
* @param headers Headers to send to the Pointercrate API.
* @param options Options to send as a JSON to the Pointercrate API.
* @returns The updated user object.
*/
async patchUser(id, headers, options = {}) {
if (isNaN(Number(id)))
throw new TypeError("Parameter id is not a number");
if (typeof headers != "object")
throw new TypeError("Parameter headers is not an object");
return this.sendAuthRequest(Endpoints.users(id), { method: "PATCH", body: options, headers });
}
/**
* Deletes a user account. This action is irreversible!
* @param id A numeric id that represents a user.
* @param headers Headers to send to the Pointercrate API.
* @returns Nothing
*/
async deleteUser(id, headers) {
if (isNaN(Number(id)))
throw new TypeError("Parameter id is not a number");
if (typeof headers != "object")
throw new TypeError("Parameter headers is not an object");
return this.sendAuthRequest(Endpoints.users(id), { method: "DELETE", headers });
}
/**
* Adds a demon to the demonlist.
* @param options Options to send as a JSON to the Pointercrate API.
* @returns The newly created demon object.
*/
async postDemon(options) {
if (typeof options != "object")
throw new TypeError("Parameter options is not an object");
return this.sendAuthRequest(Endpoints.demons(), { method: "POST", body: options });
}
/**
* Modifies a given demon.
* @param id A numeric id that represents a demon.
* @param headers Headers to send to the Pointercrate API.
* @param options Options to send as a JSON to the Pointercrate API.
* @returns The updated demon object.
*/
async patchDemon(id, headers, options = {}) {
if (isNaN(Number(id)))
throw new TypeError("Parameter id is not a number");
if (typeof headers != "object")
throw new TypeError("Parameter headers is not an object");
return this.sendAuthRequest(Endpoints.demons(id), { method: "PATCH", body: options, headers });
}
/**
* Adds a creator the creator list of the demon with the given `demonId`.
* @param demonId A numeric id that represents a demon.
* @param options Options to send as a JSON to the Pointercrate API.
* @returns Nothing
*/
async postCreator(demonId, options) {
if (isNaN(Number(demonId)))
throw new TypeError("Parameter demonId is not a number");
if (typeof options != "object")
throw new TypeError("Parameter options is not an object");
return this.sendAuthRequest(Endpoints.demonCreators(demonId), { method: "POST", body: options });
}
/**
* Removes the specified player from the creator list of the demon with the given `demonId`.
* @param demonId A numeric id that represents a demon.
* @param creatorId A numeric id that represents a player.
* @returns Nothing
*/
async deleteCreator(demonId, creatorId) {
if (isNaN(Number(demonId)))
throw new TypeError("Parameter demonId is not a number");
if (isNaN(Number(creatorId)))
throw new TypeError("Parameter creatorId is not a number");
return this.sendAuthRequest(Endpoints.demonCreators(demonId, creatorId), { method: "DELETE" });
}
/**
* Modifies a given player.
* @param id A numeric id that represents a player.
* @param headers Headers to send to the Pointercrate API.
* @param options Options to send as a JSON to the Pointercrate API.
* @returns The updated player object.
*/
async patchPlayer(id, headers, options = {}) {
if (isNaN(Number(id)))
throw new TypeError("Parameter id is not a number");
if (typeof headers != "object")
throw new TypeError("Parameter headers is not an object");
return this.sendAuthRequest(Endpoints.players(id), { method: "PATCH", body: options, headers });
}
/**
* Modifies a given record.
* @param id A numeric id that represents a record.
* @param headers Headers to send to the Pointercrate API.
* @param options Options to send as a JSON to the Pointercrate API.
* @returns The updated record object.
*/
async patchRecord(id, headers, options = {}) {
if (isNaN(Number(id)))
throw new TypeError("Parameter id is not a number");
if (typeof headers != "object")
throw new TypeError("Parameter headers is not an object");
return this.sendAuthRequest(Endpoints.records(id), { method: "PATCH", body: options, headers });
}
/**
* Deletes 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 Nothing
*/
async deleteRecord(id, headers) {
if (isNaN(Number(id)))
throw new TypeError("Parameter id is not a number");
if (typeof headers != "object")
throw new TypeError("Parameter headers is not an object");
return this.sendAuthRequest(Endpoints.records(id), { method: "DELETE", headers });
}
/**
* Adds a note to the specified record.
* @param recordId A numeric id that represents a record.
* @param options Options to send as a JSON to the Pointercrate API.
* @returns The newly created record note object.
*/
async postRecordNote(recordId, options) {
if (isNaN(Number(recordId)))
throw new TypeError("Parameter recordId is not a number");
if (typeof options != "object")
throw new TypeError("Parameter options is not an object");
return this.sendAuthRequest(Endpoints.recordNotes(recordId), { method: "POST", body: options });
}
/**
* Modifies the specified note's content.
* @param recordId A numeric id that represents a record.
* @param noteId A numeric id that represents a record note.
* @param options Options to send as a JSON to the Pointercrate API.
* @returns The updated record note object.
*/
async patchRecordNote(recordId, noteId, options) {
if (isNaN(Number(recordId)))
throw new TypeError("Parameter recordId is not a number");
if (isNaN(Number(noteId)))
throw new TypeError("Parameter creatorId is not a number");
if (typeof options != "object")
throw new TypeError("Parameter options is not an object");
return this.sendAuthRequest(Endpoints.demonCreators(recordId, noteId), { method: "PATCH", body: options });
}
/**
* Deletes the specified note.
* @param recordId A numeric id that represents a record.
* @param noteId A numeric id that represents a record note.
* @returns Nothing
*/
async deleteRecordNote(recordId, noteId) {
if (isNaN(Number(recordId)))
throw new TypeError("Parameter recordId is not a number");
if (isNaN(Number(noteId)))
throw new TypeError("Parameter creatorId is not a number");
return this.sendAuthRequest(Endpoints.recordNotes(recordId, noteId), { method: "DELETE" });
}
/**
* @param options Options to send as query parameters to the Pointercrate API.
* @returns A list of submitters.
*/
async getSubmitters(options = {}) {
return this.sendAuthRequest(Endpoints.submitters(), { body: options });
}
/**
* @param id A numeric id that represents a submitter.
* @param headers Headers to send to the Pointercrate API.
* @returns The requested submitter object.
*/
async getSubmitter(id, headers = {}) {
if (isNaN(Number(id)))
throw new TypeError("Parameter id is not a number");
return this.sendAuthRequest(Endpoints.submitters(id), { headers });
}
/**
* @param id A numeric id that represents a submitter.
* @param headers Headers to send to the Pointercrate API.
* @param options Options to send as a JSON to the Pointercrate API.
* @returns The updated submitter object.
*/
async patchSubmitter(id, headers, options = {}) {
if (isNaN(Number(id)))
throw new TypeError("Parameter id is not a number");
if (typeof headers != "object")
throw new TypeError("Parameter headers is not an object");
return this.sendAuthRequest(Endpoints.submitters(id), { method: "PATCH", body: options, headers });
}
}
module.exports = JWTAuthPointercrate;