UNPKG

@nekiro/kick-api

Version:

Efortlessly query kick.com api using easy to use interface with properly typed responses.

87 lines (86 loc) 3.33 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CategoriesModule = void 0; const errors_1 = require("../errors"); class CategoriesModule { constructor(client) { this.client = client; this.baseRoute = "/public/v1/categories"; } /** * Get categories based on search query * * Returns up to 100 results at a time; use the `page` parameter to get more results. * * @param params - Search parameters * @param params.q - Search query (required) * @param params.page - Page number (defaults to 1 if not provided) * * @returns Promise that resolves to array of categories * * @example Basic search * ```typescript * const categories = await client.categories.getCategories({ * q: "gaming" * }); * ``` * * @example Search with pagination * ```typescript * const categories = await client.categories.getCategories({ * q: "music", * page: 2 * }); * ``` * * @throws {KickBadRequestError} When search query (q) is missing * * @see https://docs.kick.com/apis/categories#get-categories */ getCategories(params) { return __awaiter(this, void 0, void 0, function* () { if (!params || !params.q) { throw new errors_1.KickBadRequestError("q is required"); } const searchParams = new URLSearchParams(); searchParams.append("q", params.q); if (params === null || params === void 0 ? void 0 : params.page) { searchParams.append("page", params.page.toString()); } return this.client.request(`${this.baseRoute}${searchParams.toString() ? `?${searchParams.toString()}` : ""}`); }); } /** * Get a specific category by ID * * @param categoryId - The ID of the category to retrieve * * @returns Promise that resolves to the category details * * @example Get category by ID * ```typescript * const category = await client.categories.getCategory(1); * console.log(category.name); // e.g., "Gaming" * ``` * * @throws {KickNotFoundError} When category with the given ID doesn't exist * @throws {KickBadRequestError} When category ID is invalid * * @see https://docs.kick.com/apis/categories#get-category */ getCategory(categoryId) { return __awaiter(this, void 0, void 0, function* () { return this.client.request(`${this.baseRoute}/${categoryId}`); }); } } exports.CategoriesModule = CategoriesModule;