UNPKG

@nekiro/kick-api

Version:

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

112 lines (111 loc) 4.76 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.LivestreamsModule = void 0; const errors_1 = require("../errors"); class LivestreamsModule { constructor(client) { this.client = client; this.baseRoute = "/public/v1/livestreams"; } /** * Get livestreams based on various filtering criteria * * Retrieve currently live streams with optional filtering by broadcaster, * category, language, and sorting options. * * @param params - Livestream filtering parameters * @param params.broadcaster_user_id - Array of broadcaster user IDs to filter by * @param params.category_id - Category ID to filter streams by * @param params.language - Language of the livestream (e.g., "en", "es", "fr") * @param params.limit - Limit the number of results (min: 1, max: 100) * @param params.sort - Sort by "viewer_count" or "started_at" * * @returns Promise that resolves to array of livestream information * * @example Get all live streams * ```typescript * const streams = await client.livestreams.getLivestreams(); * ``` * * @example Get gaming streams sorted by viewer count * ```typescript * const streams = await client.livestreams.getLivestreams({ * category_id: 1, // Gaming category * sort: "viewer_count", * limit: 20 * }); * ``` * * @example Get streams from specific broadcasters * ```typescript * const streams = await client.livestreams.getLivestreams({ * broadcaster_user_id: [12345, 67890] * }); * ``` * * @example Get English gaming streams * ```typescript * const streams = await client.livestreams.getLivestreams({ * category_id: 1, * language: "en", * sort: "viewer_count", * limit: 50 * }); * ``` * * @example Get recently started streams * ```typescript * const streams = await client.livestreams.getLivestreams({ * sort: "started_at", * limit: 10 * }); * ``` * * @throws {KickBadRequestError} When limit is outside the valid range (1-100) * @throws {KickUnauthorizedError} When not properly authenticated * * @see https://docs.kick.com/apis/livestreams#get-livestreams */ getLivestreams(params) { return __awaiter(this, void 0, void 0, function* () { const searchParams = new URLSearchParams(); // Validate limit parameter if ((params === null || params === void 0 ? void 0 : params.limit) && (params.limit < 1 || params.limit > 100)) { throw new errors_1.KickBadRequestError("limit must be between 1 and 100"); } // Add broadcaster_user_id parameters if (params === null || params === void 0 ? void 0 : params.broadcaster_user_id) { params.broadcaster_user_id.forEach((id) => { searchParams.append("broadcaster_user_id", id.toString()); }); } // Add category_id parameter if (params === null || params === void 0 ? void 0 : params.category_id) { searchParams.append("category_id", params.category_id.toString()); } // Add language parameter if (params === null || params === void 0 ? void 0 : params.language) { searchParams.append("language", params.language); } // Add limit parameter if (params === null || params === void 0 ? void 0 : params.limit) { searchParams.append("limit", params.limit.toString()); } // Add sort parameter if (params === null || params === void 0 ? void 0 : params.sort) { searchParams.append("sort", params.sort); } return this.client.request(`${this.baseRoute}${searchParams.size ? `?${searchParams.toString()}` : ""}`); }); } } exports.LivestreamsModule = LivestreamsModule;