import { AxiosError, AxiosResponse } from 'axios'; import { BaseClient, IBaseClientOptions } from './base'; import { Endpoints } from '../constants'; import { Trick, TrickError } from '../models'; /** * Tricks Client * * Client used to access Tricks endpoints: * - /tricks (https://trickingapi.dev/api/tricks) * - /tricks/names (https://trickingapi.dev/api/tricks/names) * - /tricks/:name (https://trickingapi.dev/api/tricks/:name) * * @see https://trickingapi.dev/docs */ export class TricksClient extends BaseClient { /** * @parm clientOptions options for the client */ constructor(clientOptions?: IBaseClientOptions) { super(clientOptions); } /** * Get all tricks * @returns List of tricks */ public async getAllTricks(): Promise { return new Promise((resolve, reject) => { this.api .get(`${Endpoints.Tricks}`) .then((response: AxiosResponse) => resolve(response.data)) .catch((error: AxiosError) => reject(error)); }); } /** * Get trick by name * @returns A Trick */ public async getTrickByName(name: string): Promise { return new Promise((resolve, reject) => { this.api .get(`${Endpoints.Tricks}/${name}`) .then((response: AxiosResponse) => { return resolve(response.data) }) .catch((error: AxiosError) => { reject(error) }); }); } /** * Get all trick names * @returns A list of trick names */ public async getAllTrickNames(): Promise { return new Promise((resolve, reject) => { this.api .get(`${Endpoints.Tricks}/names`) .then((response: AxiosResponse) => resolve(response.data)) .catch((error: AxiosError) => reject(error)); }); } }