Class FetcherService

The base service that handles all HTTP requests.

Hierarchy

Constructors

Properties

apiKey?: string

The api key to use for authenticating against Twitter API as user.

authProxyUrl?: URL

The URL to the proxy server to use only for authentication.

errorHandler: IErrorHandler

The service used to handle HTTP and API errors

guestKey?: string

The guest key to use for authenticating against Twitter API as guest.

proxyUrl?: URL

The URL To the proxy server to use for all others.

timeout: number

The max wait time for a response.

userId?: string

The id of the authenticated user (if any).

Methods

  • Checks the authorization status based on the requested resource.

    Parameters

    Returns void

    Throws

    An error if not authorized to access the requested resource.

  • Returns the AuthCredentials based on the type of key present.

    Returns Promise<AuthCredential>

    The generated AuthCredential

  • Gets the https agent based on whether a proxy is used or not.

    Parameters

    • Optional proxyUrl: URL

      Optional URL with proxy configuration to use for requests to Twitter API.

    Returns Agent

    The https agent to use.

  • Makes an HTTP request according to the given parameters.

    Type Parameters

    • T

      The type of the returned response data.

    Parameters

    Returns Promise<T>

    The raw data response received.

    Example

    Fetching the raw details of a user with username 'user1'

    import { FetcherService, EResourceType } from 'rettiwt-api';

    // Creating a new FetcherService instance using the given 'API_KEY'
    const fetcher = new FetcherService({ apiKey: API_KEY });

    // Fetching the details of the User with username 'user1'
    fetcher.request(EResourceType.USER_DETAILS_BY_USERNAME, { id: 'user1' })
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    })

Generated using TypeDoc