Module: TwitterLabsAPI::Resources::User

Included in:
Client
Defined in:
lib/twitter_labs_api/resources/user.rb

Constant Summary collapse

DEFAULT_USER_FIELDS =
%w[id name username].freeze
DEFAULT_FIELDS =
{ user: DEFAULT_USER_FIELDS }.freeze

Instance Method Summary collapse

Instance Method Details

#get_user(id:, fields: DEFAULT_FIELDS) ⇒ Object

Returns a variety of information about a single more user specified by the requested ID.

Parameters:

  • :id (String)

    the ID of the requested User

  • :fields (Hash)

    a hash for fields to include in the response payload;

    e.g.: { user: %w[id name username] }

Returns:

  • Hash an object with requested user fields



13
14
15
16
17
18
# File 'lib/twitter_labs_api/resources/user.rb', line 13

def get_user(id:, fields: DEFAULT_FIELDS)
  url = "https://api.twitter.com/labs/2/users/#{id}"
  params = ParamsService.from_fields(fields)

  make_request(url: url, params: params)
end

#get_users(ids:, fields: DEFAULT_FIELDS) ⇒ Array<Hash>

Returns a variety of information about one or more Users specified by the requested IDs.

Parameters:

  • :ids (Array<String>)

    the collection of requested User IDs

  • :fields (Hash)

    a hash for fields to include in the response payload;

    e.g.: { user: %w[id name username] }

Returns:

  • (Array<Hash>)

    of user objects with the requested user fields



26
27
28
29
30
31
32
# File 'lib/twitter_labs_api/resources/user.rb', line 26

def get_users(ids:, fields: DEFAULT_FIELDS)
  url = 'https://api.twitter.com/labs/2/users'
  params = ParamsService.from_fields(fields)
  params.merge!({ ids: ids.join(',') })

  make_request(url: url, params: params, is_collection: true)
end

#get_users_by_usernames(usernames:, fields: DEFAULT_FIELDS) ⇒ Array<Hash>

Returns a variety of information about one or more Users specified by the requested usernames.

Parameters:

  • :usernames (Array<String>)

    the collection of requested Usernames

  • :fields (Hash)

    a hash for fields to include in the response payload;

    e.g.: { user: %w[id name username] }

Returns:

  • (Array<Hash>)

    of user objects with the requested user fields



40
41
42
43
44
45
46
# File 'lib/twitter_labs_api/resources/user.rb', line 40

def get_users_by_usernames(usernames:, fields: DEFAULT_FIELDS)
  url = 'https://api.twitter.com/labs/2/users/by'
  params = ParamsService.from_fields(fields)
  params.merge!({ usernames: usernames.join(',') })

  make_request(url: url, params: params, is_collection: true)
end