x-api-sdk-ts
Version:
TypeScript Library for the X (ex-twitter) API V2
36 lines (35 loc) • 2.1 kB
TypeScript
import { ICustomBaseResponse, IRateLimitInfo } from "src/types/x-api/base_response";
import { IHttpAdapter } from "./IHttpAdapter";
import { IXError } from "src/types/x-api/error_responses";
export interface RCResponseSimple<T> {
data: T;
ok: boolean;
status: number;
headers: Headers;
rateLimitInfo: IRateLimitInfo;
}
export interface RCResponse<T, Others = IXError | string | null | undefined> extends RCResponseSimple<T | Others> {
}
export interface RequestOptions {
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
url: string;
headers?: Record<string, string>;
params?: Record<string, any>;
body?: any;
contentType?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data';
withCredentials?: boolean;
}
export interface IRequestClientConstructor {
new (httpAdapter: IHttpAdapter): AbstractRequestClient;
}
export declare abstract class AbstractRequestClient {
protected httpAdapter: IHttpAdapter;
constructor(httpAdapter: IHttpAdapter);
static isSuccessResponse<T>(response: RCResponse<T>): response is RCResponseSimple<T>;
isSuccessResponse<T>(response: RCResponse<T>): response is RCResponseSimple<T>;
abstract get<T extends ICustomBaseResponse>(url: string, params?: Record<string, any>, headers?: Record<string, string>): Promise<RCResponse<T>>;
abstract post<T extends ICustomBaseResponse>(url: string, body?: any, headers?: Record<string, string>, params?: Record<string, any>, contentType?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data'): Promise<RCResponse<T>>;
abstract put<T extends ICustomBaseResponse>(url: string, body?: any, headers?: Record<string, string>, params?: Record<string, any>): Promise<RCResponse<T>>;
abstract delete<T extends ICustomBaseResponse>(url: string, headers?: Record<string, string>, params?: Record<string, any>): Promise<RCResponse<T>>;
abstract patch<T extends ICustomBaseResponse>(url: string, body?: any, headers?: Record<string, string>, params?: Record<string, any>): Promise<RCResponse<T>>;
}