UNPKG

pointercrate

Version:

Unofficial Pointercrate API wrapper written in TypeScript

33 lines (32 loc) 1.23 kB
const Pointercrate = require("./Pointercrate"); /** * The base of the authentication classes. This requires an authentication token to access its endpoints. */ class BaseAuthPointercrate extends Pointercrate { /** * @param token The authentication token required. * @param type The authentication type used. * @param api An optional url string specifing what API to send requests to. */ constructor(token, type, api = "https://pointercrate.com/api") { super(api); this.token = token; this.type = type; } /** * A function to send authenticated requests to the Pointercrate API. * @param path The path to the endpoint of the request. * @param options Options to send into the request, if specified. * @returns A response, containing a `body`, and `headers`. */ async sendAuthRequest(path, options = { method: "GET", headers: {}, body: {} }) { return this.sendRequest(this.api + path, { ...options, headers: { ...options.headers, Authorization: this.type + " " + this.token } }); } } module.exports = BaseAuthPointercrate;