/** * Basic, generic API method, requires some attributes * and the implementation of the request() method. * * `type: { new(value: any): T } `, means that you have to pass a new-able object (a.k.a., a class). * It will use `new type()` to parse the response and return the resulting object. * * `BaseAPIMethod` can be extended to define more complex requests. but a basic implementation is given by the {@link APIMethod} generic class. */ export declare abstract class BaseAPIMethod { protected token?: string; protected device_id?: string; protected signature?: string; protected abstract path: string; protected abstract method: string; protected abstract body?: string; constructor(token?: string, device_id?: string, signature?: string); abstract request(...args: any): Promise; } /** * Generic, abstract class to simplify the api method implementation. * * Requires `path`, `method`, `body` and `request()` to be defined when this abstract class is implemented. * Check out an exmaple class that implements an api call: * * @example * ``` * * class APIResponse {// Parser for the response body * my_name: string * constructor(values: any) { this.my_name = values.response_name; } * } * * class APIRequest extends APIMethod { * path = 'https://my.api.test/get/name' * method = 'GET' * body = JSON.stringify({ user: 'john' }) * async request() { return await this._request(APIResponse); } * } * * const x = await new APIRequest('some_token').request() // {my_name: 'John Doe'} * ``` * Or if you are in the mood for some TypeScript fuckery: * @example * ``` * function cat(values: any) { * let object = {} * console.log('nicer') * object.lol = 'nice' * return object * } * * class CatRequest extends APIMethod { * path = 'https://my.api.test/get/cats' * method = 'GET' * body = JSON.stringify({ please: 'and thank you' }) * async request() { return await this._request(cat as any) as typeof cat; } * } * * const y = await new CatRequest('some_token').request() // {lol: 'nice'} * ``` */ declare abstract class APIMethod extends BaseAPIMethod { protected _request(type: { new (value: any): T; }): Promise; } export declare abstract class PrivateAPIMethod extends APIMethod { constructor(token: string); } export declare abstract class PrivateWithIDAPIMethod extends APIMethod { protected device_id: string; constructor(token: string, device_id: string); } export declare abstract class PublicAPIMethod extends APIMethod { constructor(); } export {};