samira
Version:
A TypeScript library for League of Legends API calls
79 lines • 2.14 kB
TypeScript
import { AxiosRequestConfig } from 'axios';
import { Either } from '../types/either';
import { type Platform, type Region } from '../constants';
export interface HttpClientConfig {
baseURL: string;
apiKey?: string;
timeout?: number;
retries?: number;
retryDelay?: number;
}
export interface ApiResponse<T> {
data: T;
status: number;
statusText: string;
headers: Record<string, string>;
}
export interface ApiError {
status: number;
statusText: string;
message: string;
details?: any;
}
export declare class HttpClient {
private client;
private rateLimiter;
private config;
constructor(config: HttpClientConfig);
/**
* Make a GET request
*/
get<T>(url: string, config?: AxiosRequestConfig): Promise<Either<ApiError, ApiResponse<T>>>;
/**
* Make a GET request with retry logic
*/
requestWithRetry<T>(url: string, config?: AxiosRequestConfig): Promise<Either<ApiError, ApiResponse<T>>>;
/**
* Update the API key
*/
updateApiKey(apiKey: string): void;
/**
* Update the base URL
*/
updateBaseURL(baseURL: string): void;
/**
* Get rate limiter status
*/
getRateLimitStatus(): {
canMakeRequest: boolean;
delayUntilNext: number;
requestsInWindow: number;
dailyRequests: number;
};
/**
* Reset rate limiter
*/
resetRateLimiter(): void;
/**
* Format axios response to our standard format
*/
private formatResponse;
/**
* Format axios error to our standard format
*/
private formatError;
/**
* Get user-friendly error messages for common HTTP status codes
*/
private getErrorMessage;
}
/**
* Create an HTTP client for a specific platform
*/
export declare function createPlatformClient(platform: Platform, apiKey: string): HttpClient;
/**
* Create an HTTP client for regional routing
*/
export declare function createRegionalClient(region: Region, apiKey: string): HttpClient;
export declare function createDataDragonClient(): HttpClient;
//# sourceMappingURL=httpClient.d.ts.map