Class ListService

The base service that handles all HTTP requests.

Hierarchy (View Summary)

Constructors

Properties

config: RettiwtConfig

The config object.

Methods

  • Add a user as a member of a list.

    Parameters

    • listId: string

      The ID of the target list.

    • userId: string

      The ID of the target user to be added as a member.

    Returns Promise<undefined | number>

    The new member count of the list. If adding was unsuccessful, return undefined.

    import { Rettiwt } from 'rettiwt-api';

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

    // Adding a user with ID '123456789' as a member to the list with ID '987654321'
    rettiwt.list.addMember('987654321', '123456789')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Create a list.

    Parameters

    • list: INewList

      The details of the list to create.

    Returns Promise<undefined | string>

    The ID of the created list. If creation was unsuccessful, return undefined.

    import { Rettiwt } from 'rettiwt-api';

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

    // Creating a public list
    rettiwt.list.create({ name: 'My list', description: 'List description', isPrivate: false })
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Delete a list.

    Parameters

    • id: string

      The ID of the list to delete.

    Returns Promise<boolean>

    Whether deletion was successful.

    import { Rettiwt } from 'rettiwt-api';

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

    // Deleting the list with ID '1234567890'
    rettiwt.list.delete('1234567890')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Get the details of a list.

    Parameters

    • id: string

      The ID of the target list.

    Returns Promise<undefined | List>

    The details of the target list.

    If list not found, returns undefined.

    import { Rettiwt } from 'rettiwt-api';

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

    // Fetching the details of the list with the id '1234567890'
    rettiwt.list.details('1234567890')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Get the list of members of a tweet list.

    Parameters

    • id: string

      The ID of target list.

    • Optionalcount: number

      The number of members to fetch, must be <= 100.

    • Optionalcursor: string

      The cursor to the batch of members to fetch.

    Returns Promise<CursoredData<User>>

    The list tweets in the given list.

    import { Rettiwt } from 'rettiwt-api';

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

    // Fetching the first 100 members of the Twitter list with id '1234567890'
    rettiwt.list.members('1234567890')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });

    Due a bug in Twitter API, the count is ignored when no cursor is provided and defaults to 100.

  • Mute a list.

    Parameters

    • id: string

      The ID of the list to mute.

    Returns Promise<boolean>

    Whether muting was successful.

    import { Rettiwt } from 'rettiwt-api';

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

    // Muting the list with ID '1234567890'
    rettiwt.list.mute('1234567890')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Remove a member from a list.

    Parameters

    • listId: string

      The ID of the target list.

    • userId: string

      The ID of the target user to removed from the members.

    Returns Promise<undefined | number>

    The new member count of the list. If removal was unsuccessful, return undefined.

    import { Rettiwt } from 'rettiwt-api';

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

    // Removing a user with ID '123456789' from the member of the list with ID '987654321'
    rettiwt.list.removeMember('987654321', '123456789')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Makes an HTTP request according to the given parameters.

    Type Parameters

    • T = unknown

      The type of the returned response data.

    Parameters

    Returns Promise<AxiosResponse<T, any, {}>>

    The raw Axios response.

    import { FetcherService, ResourceType } 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(ResourceType.USER_DETAILS_BY_USERNAME, { id: 'user1' })
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Get the list of tweets from a tweet list.

    Parameters

    • id: string

      The ID of target list.

    • Optionalcount: number

      The number of tweets to fetch, must be <= 100.

    • Optionalcursor: string

      The cursor to the batch of tweets to fetch.

    Returns Promise<CursoredData<Tweet>>

    The list tweets in the given list.

    import { Rettiwt } from 'rettiwt-api';

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

    // Fetching the most recent 100 tweets of the Twitter list with id '1234567890'
    rettiwt.list.tweets('1234567890')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });

    Due a bug in Twitter API, the count is ignored when no cursor is provided and defaults to 100.

  • Unmute a list.

    Parameters

    • id: string

      The ID of the list to unmute.

    Returns Promise<boolean>

    Whether unmuting was successful.

    import { Rettiwt } from 'rettiwt-api';

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

    // Unmuting the list with ID '1234567890'
    rettiwt.list.unmute('1234567890')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Update a list.

    Parameters

    • id: string

      The ID of the list to update.

    • updates: IListUpdates

      The updates to apply to the list.

    Returns Promise<undefined | List>

    The updated list. If update was unsuccessful, return undefined.

    Fields omitted from updates are left unchanged. Use an empty string for description to clear the existing description.

    import { Rettiwt } from 'rettiwt-api';

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

    // Updating the list with ID '1234567890'
    rettiwt.list.update('1234567890', { name: 'My list', description: 'List description', isPrivate: false })
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });