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