twitter-api-v2
Version:
Strongly typed, full-featured, light, versatile yet powerful Twitter API v1.1 and v2 client for Node.js.
112 lines (111 loc) • 5.57 kB
TypeScript
import { TClientTokens, TwitterApiBasicAuth, TwitterApiOAuth2Init, TwitterApiTokens, TwitterRateLimit, TwitterResponse, UserV1 } from './types';
import { ClientRequestMaker, TCustomizableRequestArgs, TRequestBody, TRequestQuery } from './client-mixins/request-maker.mixin';
import TweetStream from './stream/TweetStream';
export declare type TGetClientRequestArgs = TCustomizableRequestArgs & {
prefix?: string;
fullResponse?: boolean;
};
declare type TGetClientRequestArgsFullResponse = TClientRequestArgs & {
fullResponse: true;
};
declare type TGetClientRequestArgsDataResponse = TClientRequestArgs & {
fullResponse?: false;
};
export declare type TClientRequestArgs = TCustomizableRequestArgs & {
prefix?: string;
fullResponse?: boolean;
query?: TRequestQuery;
};
declare type TClientRequestArgsFullResponse = TClientRequestArgs & {
fullResponse: true;
};
declare type TClientRequestArgsDataResponse = TClientRequestArgs & {
fullResponse?: false;
};
export declare type TStreamClientRequestArgs = TCustomizableRequestArgs & {
prefix?: string;
query?: TRequestQuery;
payloadIsError?: (data: any) => boolean;
/**
* Choose to make or not initial connection.
* Method `.connect` must be called on returned `TweetStream` object
* to start stream if `autoConnect` is set to `false`.
* Defaults to `true`.
*/
autoConnect?: boolean;
};
export declare type TStreamClientRequestArgsWithAutoConnect = TStreamClientRequestArgs & {
autoConnect?: true;
};
export declare type TStreamClientRequestArgsWithoutAutoConnect = TStreamClientRequestArgs & {
autoConnect: false;
};
/**
* Base class for Twitter instances
*/
export default abstract class TwitterApiBase extends ClientRequestMaker {
protected _prefix: string | undefined;
protected _currentUser: UserV1 | null;
/**
* Create a new TwitterApi object without authentification.
*/
constructor();
/**
* Create a new TwitterApi object with OAuth 2.0 Bearer authentification.
*/
constructor(bearerToken: string);
/**
* Create a new TwitterApi object with three-legged OAuth 1.0a authentification.
*/
constructor(tokens: TwitterApiTokens);
/**
* Create a new TwitterApi object with only client ID needed for OAuth2 user-flow.
*/
constructor(oauth2Init: TwitterApiOAuth2Init);
/**
* Create a new TwitterApi object with Basic HTTP authentification.
*/
constructor(credentials: TwitterApiBasicAuth);
/**
* Create a clone of {instance}.
*/
constructor(instance: TwitterApiBase);
protected setPrefix(prefix: string | undefined): void;
cloneWithPrefix(prefix: string): this;
getActiveTokens(): TClientTokens;
/**
* Tells if you hit the Twitter rate limit for {endpoint}.
* (local data only, this should not ask anything to Twitter)
*/
hasHitRateLimit(endpoint: string): boolean;
/**
* Tells if you hit the returned Twitter rate limit for {endpoint} has expired.
* If client has no saved rate limit data for {endpoint}, this will gives you `true`.
*/
isRateLimitStatusObsolete(endpoint: string): boolean;
/**
* Get the last obtained Twitter rate limit information for {endpoint}.
* (local data only, this should not ask anything to Twitter)
*/
getLastRateLimitStatus(endpoint: string): TwitterRateLimit | undefined;
/** Get cached current user. */
protected getCurrentUserObject(forceFetch?: boolean): Promise<UserV1>;
get<T = any>(url: string, query?: TRequestQuery, args?: TGetClientRequestArgsDataResponse): Promise<T>;
get<T = any>(url: string, query?: TRequestQuery, args?: TGetClientRequestArgsFullResponse): Promise<TwitterResponse<T>>;
delete<T = any>(url: string, query?: TRequestQuery, args?: TGetClientRequestArgsDataResponse): Promise<T>;
delete<T = any>(url: string, query?: TRequestQuery, args?: TGetClientRequestArgsFullResponse): Promise<TwitterResponse<T>>;
post<T = any>(url: string, body?: TRequestBody, args?: TClientRequestArgsDataResponse): Promise<T>;
post<T = any>(url: string, body?: TRequestBody, args?: TClientRequestArgsFullResponse): Promise<TwitterResponse<T>>;
put<T = any>(url: string, body?: TRequestBody, args?: TClientRequestArgsDataResponse): Promise<T>;
put<T = any>(url: string, body?: TRequestBody, args?: TClientRequestArgsFullResponse): Promise<TwitterResponse<T>>;
patch<T = any>(url: string, body?: TRequestBody, args?: TClientRequestArgsDataResponse): Promise<T>;
patch<T = any>(url: string, body?: TRequestBody, args?: TClientRequestArgsFullResponse): Promise<TwitterResponse<T>>;
/** Stream request helpers */
getStream<T = any>(url: string, query: TRequestQuery | undefined, options: TStreamClientRequestArgsWithoutAutoConnect): TweetStream<T>;
getStream<T = any>(url: string, query?: TRequestQuery, options?: TStreamClientRequestArgsWithAutoConnect): Promise<TweetStream<T>>;
getStream<T = any>(url: string, query?: TRequestQuery, options?: TStreamClientRequestArgs): Promise<TweetStream<T>> | TweetStream<T>;
postStream<T = any>(url: string, body: TRequestBody | undefined, options: TStreamClientRequestArgsWithoutAutoConnect): TweetStream<T>;
postStream<T = any>(url: string, body?: TRequestBody, options?: TStreamClientRequestArgsWithAutoConnect): Promise<TweetStream<T>>;
postStream<T = any>(url: string, body?: TRequestBody, options?: TStreamClientRequestArgs): Promise<TweetStream<T>> | TweetStream<T>;
}
export {};