UNPKG

igdb-client

Version:

70 lines 2.75 kB
import type { Game } from "igdb-types"; export declare class IGDBClient { private readonly clientID; private readonly clientSecret; private readonly grantType; private readonly authURL; private igdbBaseURL; private axiosClient; private accessToken; private expiresIn; private isConnected; private tokenTimeout; /** * Get the request header that contains the Client ID and access token. * * This method throws an error if the client is not connected. * * @returns The request headers object. * @throws {Error} If the client is not connected. */ private getRequestHeader; /** * Construct a new IGDBClient instance. If no client ID or secret is provided, it will use the TWITCH_CLIENT_ID and TWITCH_CLIENT_SECRET environment variables. * * @param twitchClientID Your Twitch Developer Dashboard client ID. * @param twitchClientSecret Your Twitch Developer Dashboard client secret. */ constructor(twitchClientID?: string, twitchClientSecret?: string); /** * Connects to the IGDB API by getting an access token using the Twitch client credentials. * Updates the request header with the new access token for authentication. * * @returns {Promise<this>} Returns the IGDBClient instance on successful connection, * or an error if the connection fails. */ connect(): Promise<this>; /** * Disconnects from the IGDB API by clearing the access token timeout and setting the connection status to false. * * @returns {void} Does not return any value. */ disconnect(): void; /** * Requests an access token using the Twitch client credentials. * Updates the request header with the new access token for authentication. * Refreshes the access token when it is about to expire. * * @returns {Promise<void>} Resolves when the access token is set. * @throws {Error} If the request for an access token fails. * @private */ private getAccessToken; /** * Fetches a list of games from the IGDB API that match the given name. * * @param name - The name of the game to search for. * @returns A promise that resolves to the list of games matching the search query. * @throws Logs an error if the request fails. */ getGames(name: string): Promise<Game[]>; /** * Fetches a game by its ID from the IGDB API. * * @param id - The ID of the game to fetch. * @returns A promise that resolves to the fetched game. * @throws Logs an error if the request fails. */ getGame(id: number): Promise<Game[]>; } //# sourceMappingURL=IGDBClient.d.ts.map