import { ApiRootResponse } from '../twitch'; import { ApiOptions, ApiReadyStates, ApiFetchOptions } from './types'; export * from './types'; /** * Make requests to Twitch API. * * ## Initializing * * ```js * // With a token ... * const token = 'cfabdegwdoklmawdzdo98xt2fo512y' * const { api } = new TwitchJs({ token }) * * // ... or with a client ID ... * const clientId = 'uo6dggojyb8d6soh92zknwmi5ej1q2' * const { api } = new TwitchJs({ clientId }) * ``` * * **Note:** The recommended way to initialize the API client is with a token. * * ## Making requests * * By default, the API client makes requests to the * [Helix API](https://dev.twitch.tv/docs/api), and exposes [[Api.get]], * [[Api.post]] and [[Api.put]] methods. Query string parameters and body * parameters are provided via `options.search` and `options.body` properties, * respectively. * * To make requests to the [Kraken/v5 API](https://dev.twitch.tv/docs/v5), use * `options.version = 'kraken'` * * ### Examples * * #### Get bits leaderboard * ```js * api * .get('bits/leaderboard', { search: { user_id: '44322889' } }) * .then(response => { * // Do stuff with response ... * }) * ``` * * #### Get the latest Overwatch live streams * ``` * api * .get('streams', { version: 'kraken', search: { game: 'Overwatch' } }) * .then(response => { * // Do stuff with response ... * }) * ``` * * #### Start a channel commercial * ``` * const channelId = '44322889' * api * .post(`channels/${channelId}/commercial`, { * version: 'kraken', * body: { length: 30 }, * }) * .then(response => { * // Do stuff with response ... * }) * ``` */ declare class Api { private _options; private _log; private _readyState; private _status; constructor(maybeOptions?: ApiOptions); set options(maybeOptions: ApiOptions); get options(): ApiOptions; get readyState(): ApiReadyStates; get status(): ApiRootResponse; /** * New client options. To update `token` or `clientId`, use [**api.initialize()**]{@link Api#initialize}. */ updateOptions(options: Partial): void; /** * Initialize API client and retrieve status. * @see https://dev.twitch.tv/docs/v5/#root-url */ initialize(newOptions?: Partial): Promise; /** * Check if current credentials include `scope`. * @see https://dev.twitch.tv/docs/authentication/#twitch-api-v5 */ hasScope( /** Scope to check */ scope: string): Promise; /** * GET endpoint. * * @example Get Live Overwatch Streams (Kraken) * ``` * api.get('streams', { version: 'kraken', search: { game: 'Overwatch' } }) * .then(response => { * // Do stuff with response ... * }) * ``` * * @example Get user follows (Helix) * ``` * api.get('users/follows', { search: { to_id: '23161357' } }) * .then(response => { * // Do stuff with response ... * }) * ``` */ get(endpoint?: string, options?: ApiFetchOptions): Promise; /** * POST endpoint. */ post(endpoint: string, options?: ApiFetchOptions): Promise; /** * PUT endpoint. */ put(endpoint: string, options?: ApiFetchOptions): Promise; private _isVersionHelix; private _getBaseUrl; private _getHeaders; private _handleFetch; } export default Api;