pointercrate
Version:
Unofficial Pointercrate API wrapper written in TypeScript
51 lines (50 loc) • 2.17 kB
JavaScript
const BaseAuthPointercrate = require("./BaseAuthPointercrate");
const Endpoints = require("./Endpoints");
/**
* Pointercrate authentication class. Type: Basic.
*/
class BasicAuthPointercrate 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, "Basic", api);
}
/**
* Logs into an existing pointercrate user account, providing an acccess token upon success.
* @returns A user object representing the account you just logged into, and your access token to use when performing requests to the Pointercrate API.
*/
async loginAccount() {
return this.sendAuthRequest(Endpoints.auth(), { method: "POST" });
}
/**
* Invalidates all access tokens to your account.
* @returns Nothing
*/
async invalidateTokens() {
return this.sendAuthRequest(Endpoints.invalidateAuth(), { method: "POST" });
}
/**
* Modifies the currently logged in account (that is, the account whose credentials are sent).
* @param headers Headers to send to the Pointercrate API.
* @param options Options to send as a JSON to the Pointercrate API.
* @returns A user object representing the account you just logged into.
*/
async patchAccount(headers, options = {}) {
if (typeof headers != "object")
throw new TypeError("Parameter headers is not an object");
return this.sendAuthRequest(Endpoints.meAuth(), { method: "PATCH", body: options });
}
/**
* Deletes your pointercrate account. Note that this action is irreversible!
* @param headers Headers to send to the Pointercrate API.
* @returns Nothing
*/
async deleteAccount(headers) {
if (typeof headers != "object")
throw new TypeError("Parameter headers is not an object");
return this.sendAuthRequest(Endpoints.meAuth(), { method: "DELETE" });
}
}
module.exports = BasicAuthPointercrate;