Module: Twitter::Client::Users

Included in:
Twitter::Client
Defined in:
lib/twitter/client/users.rb

Overview

Defines methods related to users

Instance Method Summary collapse

Instance Method Details

#contributees(options = {}) ⇒ Array<Twitter::User> #contributees(user, options = {}) ⇒ Array<Twitter::User>

Returns an array of users that the specified user can contribute to

Overloads:

  • #contributees(options = {}) ⇒ Array<Twitter::User>

    Examples:

    Return the authenticated user's contributees

    Twitter.contributees

    Parameters:

    • options (Hash) (defaults to: {})

      A customizable set of options.

    Options Hash (options):

    • :include_entities (Boolean, String, Integer)

      Include Tweet Entities when set to true, 't' or 1.

    • :skip_status (Boolean, String, Integer)

      Do not include contributee's statuses when set to true, 't' or 1.

    Returns:

  • #contributees(user, options = {}) ⇒ Array<Twitter::User>

    Examples:

    Return users @sferik can contribute to

    Twitter.contributees("sferik")
    Twitter.contributees(7505382)  # Same as above

    Parameters:

    • user (Integer, String)

      A Twitter user ID or screen name.

    • options (Hash) (defaults to: {})

      A customizable set of options.

    Options Hash (options):

    • :include_entities (Boolean, String, Integer)

      Include Tweet Entities when set to true, 't' or 1.

    • :skip_status (Boolean, String, Integer)

      Do not include contributee's statuses when set to true, 't' or 1.

    Returns:

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • No unless requesting it from a protected user

    If getting this data of a protected user, you must authenticate (and be allowed to see that user).



137
138
139
140
141
142
143
144
145
# File 'lib/twitter/client/users.rb', line 137

def contributees(*args)
  options = {}
  options.merge!(args.last.is_a?(Hash) ? args.pop : {})
  user = args.pop || self.current_user.screen_name
  options.merge_user!(user)
  get("/1/users/contributees.json", options).map do |user|
    Twitter::User.new(user)
  end
end

#contributors(options = {}) ⇒ Array<Twitter::User> #contributors(user, options = {}) ⇒ Array<Twitter::User>

Returns an array of users who can contribute to the specified account

Overloads:

  • #contributors(options = {}) ⇒ Array<Twitter::User>

    Examples:

    Return the authenticated user's contributors

    Twitter.contributors

    Parameters:

    • options (Hash) (defaults to: {})

      A customizable set of options.

    Options Hash (options):

    • :include_entities (Boolean, String, Integer)

      Include Tweet Entities when set to true, 't' or 1.

    • :skip_status (Boolean, String, Integer)

      Do not include contributee's statuses when set to true, 't' or 1.

    Returns:

  • #contributors(user, options = {}) ⇒ Array<Twitter::User>

    Examples:

    Return users who can contribute to @sferik's account

    Twitter.contributors("sferik")
    Twitter.contributors(7505382)  # Same as above

    Parameters:

    • user (Integer, String)

      A Twitter user ID or screen name.

    • options (Hash) (defaults to: {})

      A customizable set of options.

    Options Hash (options):

    • :include_entities (Boolean, String, Integer)

      Include Tweet Entities when set to true, 't' or 1.

    • :skip_status (Boolean, String, Integer)

      Do not include contributee's statuses when set to true, 't' or 1.

    Returns:

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • No unless requesting it from a protected user

    If getting this data of a protected user, you must authenticate (and be allowed to see that user).



170
171
172
173
174
175
176
177
178
# File 'lib/twitter/client/users.rb', line 170

def contributors(*args)
  options = {}
  options.merge!(args.last.is_a?(Hash) ? args.pop : {})
  user = args.pop || self.current_user.screen_name
  options.merge_user!(user)
  get("/1/users/contributors.json", options).map do |user|
    Twitter::User.new(user)
  end
end

#profile_image(screen_name, options = {}) ⇒ String

Access the profile image in various sizes for the user with the indicated screen name

Examples:

Return the URL for the 24px by 24px version of @sferik's profile image

Twitter.profile_image("sferik", :size => 'mini')

Parameters:

  • screen_name (String)

    The screen name of the user for whom to return results for.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :size (String) — default: 'normal'

    Specifies the size of image to fetch. Valid options include: 'bigger' (73px by 73px), 'normal' (48px by 48px), and 'mini' (24px by 24px).

Returns:

  • (String)

    The URL for the requested user's profile image.

See Also:

Rate Limited?:

  • No

Requires Authentication?:

  • No



47
48
49
50
51
# File 'lib/twitter/client/users.rb', line 47

def profile_image(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  screen_name = args.pop || self.current_user.screen_name
  get("/1/users/profile_image/#{screen_name}", options, :raw => true).headers['location']
end

#recommendations(options = {}) ⇒ Array<Twitter::User>

Note:

Returns recommended users for the authenticated user

Examples:

Return recommended users for the authenticated user

Twitter.recommendations

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :limit (Integer) — default: 20

    Specifies the number of records to retrieve.

  • :excluded (String)

    Comma-separated list of user IDs to exclude.

  • :screen_name (String)

    Find users similar to this screen_name

  • :user_id (Integer)

    Find users similar to this user ID.

Returns:

Raises:

Rate Limited?:

  • Yes

Requires Authentication?:

  • Yes



194
195
196
197
198
199
# File 'lib/twitter/client/users.rb', line 194

def recommendations(options={})
  options[:excluded] = options[:excluded].join(',') if options[:excluded].is_a?(Array)
  get("/1/users/recommendations.json", options).map do |recommendation|
    Twitter::User.new(recommendation['user'])
  end
end

#user(user, options = {}) ⇒ Twitter::User

Returns extended information of a given user

Returns The requested user.

Examples:

Return extended information for @sferik

Twitter.user("sferik")
Twitter.user(7505382)  # Same as above

Parameters:

  • user (Integer, String)

    A Twitter user ID or screen name.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

Returns:

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • No



86
87
88
89
90
91
92
93
94
95
# File 'lib/twitter/client/users.rb', line 86

def user(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  if user = args.pop
    options.merge_user!(user)
    user = get("/1/users/show.json", options)
  else
    user = get("/1/account/verify_credentials.json", options)
  end
  Twitter::User.new(user)
end

#user?(user, options = {}) ⇒ Boolean

Returns true if the specified user exists

Examples:

Return true if @sferik exists

Twitter.user?("sferik")
Twitter.user?(7505382)  # Same as above

Parameters:

  • user (Integer, String)

    A Twitter user ID or screen name.

Returns:

  • (Boolean)

    true if the user exists, otherwise false.

Rate Limited?:

  • Yes

Requires Authentication?:

  • No



106
107
108
109
110
111
112
# File 'lib/twitter/client/users.rb', line 106

def user?(user, options={})
  options.merge_user!(user)
  get("/1/users/show.json", options, :raw => true)
  true
rescue Twitter::Error::NotFound
  false
end

#user_search(query, options = {}) ⇒ Array<Twitter::User>

Returns users that match the given query

Examples:

Return users that match "Erik Michaels-Ober"

Twitter.user_search("Erik Michaels-Ober")

Parameters:

  • query (String)

    The search query to run against people search.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :per_page (Integer)

    The number of people to retrieve. Maxiumum of 20 allowed per page.

  • :page (Integer)

    Specifies the page of results to retrieve.

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • Yes



67
68
69
70
71
# File 'lib/twitter/client/users.rb', line 67

def user_search(query, options={})
  get("/1/users/search.json", options.merge(:q => query)).map do |user|
    Twitter::User.new(user)
  end
end

#users(*users, options = {}) ⇒ Array<Twitter::User>

Returns extended information for up to 100 users

Returns The requested users.

Examples:

Return extended information for @sferik and @pengwynn

Twitter.users("sferik", "pengwynn")
Twitter.users("sferik", 14100886)   # Same as above
Twitter.users(7505382, 14100886)    # Same as above

Parameters:

  • users (Array<Integer, String>, Set<Integer, String>)

    Twitter user IDs or screen names.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • Yes



26
27
28
29
30
31
32
33
# File 'lib/twitter/client/users.rb', line 26

def users(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  users = args
  options.merge_users!(Array(users))
  get("/1/users/lookup.json", options).map do |user|
    Twitter::User.new(user)
  end
end