Module: Twttr::Client::Endpoint::V2::Users::Follows

Included in:
Twttr::Client
Defined in:
lib/twttr/client/endpoint/v2/users/follows.rb

Overview

Twitter API V2 User Follow related endpoints developer.twitter.com/en/docs/twitter-api/users/follows/api-reference

Constant Summary collapse

FOLLOWING_PATH =
"#{Users::USER_PATH}/following"

Instance Method Summary collapse

Instance Method Details

#following(user_id, max_results: nil, pagination_token: nil) {|Array<Twttr::Model::User>| ... } ⇒ Array<Twttr::Model::User>, ...

Parameters:

  • user_id (String)

    The user ID whose following you would like to retrieve.

  • max_results (Integer) (defaults to: nil)

    Max number of results per peage.

  • pagination_token (String) (defaults to: nil)

    Initial page pagination token.

Yields:

Returns:

  • (Array<Twttr::Model::User>)

    Users followed.

  • (String, NilClass)

    Pagination token.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/twttr/client/endpoint/v2/users/follows.rb', line 22

def following(user_id, max_results: nil, pagination_token: nil) # rubocop:disable Metrics/MethodLength
  loop do
    response = get(FOLLOWING_PATH, params: { user_id: user_id },
                                   query_params: {
                                     'user.fields': config.user_fields,
                                     max_results: max_results,
                                     pagination_token: pagination_token
                                   }.compact)

    users = response['data'].map { |v| Model::User.new(v, self) }

    pagination_token = response['meta']['pagination_token']

    return users, pagination_token unless block_given?

    yield users, pagination_token

    break if pagination_token.nil?
  end
end