Module: Twitter::REST::FriendsAndFollowers

Includes:
Utils, Utils
Included in:
API
Defined in:
lib/twitter/rest/friends_and_followers.rb

Constant Summary

Constants included from Utils

Utils::DEFAULT_CURSOR

Instance Method Summary collapse

Methods included from Utils

flat_pmap, pmap

Instance Method Details

#follow(*users) ⇒ Array<Twitter::User> #follow(*users, options) ⇒ Array<Twitter::User> Also known as: create_friendship

Allows the authenticating user to follow the specified users, unless they are already followed

Overloads:

  • #follow(*users) ⇒ Array<Twitter::User>

    Parameters:

    • users (Enumerable<Integer, String, Twitter::User>)

      A collection of Twitter user IDs, screen names, or objects.

  • #follow(*users, options) ⇒ Array<Twitter::User>

    Parameters:

    • users (Enumerable<Integer, String, Twitter::User>)

      A collection of Twitter user IDs, screen names, or objects.

    • options (Hash)

      A customizable set of options.

    Options Hash (options):

    • :follow (Boolean) — default: false

      Enable notifications for the target user.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



106
107
108
109
110
111
112
113
114
115
# File 'lib/twitter/rest/friends_and_followers.rb', line 106

def follow(*args)
  arguments = Twitter::Arguments.new(args)
  existing_friends = Thread.new do
    friend_ids.to_a
  end
  new_friends = Thread.new do
    users(args).collect(&:id)
  end
  follow!(new_friends.value - existing_friends.value, arguments.options)
end

#follow!(*users) ⇒ Array<Twitter::User> #follow!(*users, options) ⇒ Array<Twitter::User> Also known as: create_friendship!

Allows the authenticating user to follow the specified users

Overloads:

  • #follow!(*users) ⇒ Array<Twitter::User>

    Parameters:

    • users (Enumerable<Integer, String, Twitter::User>)

      A collection of Twitter user IDs, screen names, or objects.

  • #follow!(*users, options) ⇒ Array<Twitter::User>

    Parameters:

    • users (Enumerable<Integer, String, Twitter::User>)

      A collection of Twitter user IDs, screen names, or objects.

    • options (Hash)

      A customizable set of options.

    Options Hash (options):

    • :follow (Boolean) — default: false

      Enable notifications for the target user.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



131
132
133
134
135
136
# File 'lib/twitter/rest/friends_and_followers.rb', line 131

def follow!(*args)
  arguments = Twitter::Arguments.new(args)
  pmap(arguments) do |user|
    perform_post_with_object("/1.1/friendships/create.json", merge_user(arguments.options, user), Twitter::User)
  end.compact
end

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

Overloads:

  • #follower_ids(options = {}) ⇒ Twitter::Cursor

    Returns an array of numeric IDs for every user following the authenticated user

    Parameters:

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

      A customizable set of options.

  • #follower_ids(user, options = {}) ⇒ Twitter::Cursor

    Returns an array of numeric IDs for every user following the specified user

    Parameters:

    • user (Integer, String, Twitter::User)

      A Twitter user ID, screen name, URI, or object.

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

      A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



47
48
49
# File 'lib/twitter/rest/friends_and_followers.rb', line 47

def follower_ids(*args)
  cursor_from_response_with_user(:ids, nil, "/1.1/followers/ids.json", args)
end

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

Returns a cursored collection of user objects for users following the specified user.

Overloads:

  • #followers(options = {}) ⇒ Twitter::Cursor

    Returns a cursored collection of user objects for users following the authenticated user.

    Parameters:

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

      A customizable set of options.

    Options Hash (options):

    • :skip_status (Boolean, String, Integer)

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

    • :include_user_entities (Boolean, String, Integer)

      The user entities node will be disincluded when set to false.

  • #followers(user, options = {}) ⇒ Twitter::Cursor

    Returns a cursored collection of user objects for users following the specified user.

    Parameters:

    • user (Integer, String, Twitter::User)

      A Twitter user ID, screen name, URI, or object.

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

      A customizable set of options.

    Options Hash (options):

    • :skip_status (Boolean, String, Integer)

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

    • :include_user_entities (Boolean, String, Integer)

      The user entities node will be disincluded when set to false.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



227
228
229
# File 'lib/twitter/rest/friends_and_followers.rb', line 227

def followers(*args)
  cursor_from_response_with_user(:users, Twitter::User, "/1.1/followers/list.json", args)
end

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

Overloads:

  • #friend_ids(options = {}) ⇒ Twitter::Cursor

    Returns an array of numeric IDs for every user the authenticated user is following

    Parameters:

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

      A customizable set of options.

  • #friend_ids(user, options = {}) ⇒ Twitter::Cursor

    Returns an array of numeric IDs for every user the specified user is following

    Parameters:

    • user (Integer, String, Twitter::User)

      A Twitter user ID, screen name, URI, or object.

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

      A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



29
30
31
# File 'lib/twitter/rest/friends_and_followers.rb', line 29

def friend_ids(*args)
  cursor_from_response_with_user(:ids, nil, "/1.1/friends/ids.json", args)
end

#friends(options = {}) ⇒ Twitter::Cursor #friends(user, options = {}) ⇒ Twitter::Cursor Also known as: following

Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends").

Overloads:

  • #friends(options = {}) ⇒ Twitter::Cursor

    Returns a cursored collection of user objects for every user the authenticated user is following (otherwise known as their "friends").

    Parameters:

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

      A customizable set of options.

    Options Hash (options):

    • :skip_status (Boolean, String, Integer)

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

    • :include_user_entities (Boolean, String, Integer)

      The user entities node will be disincluded when set to false.

  • #friends(user, options = {}) ⇒ Twitter::Cursor

    Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends").

    Parameters:

    • user (Integer, String, Twitter::User)

      A Twitter user ID, screen name, URI, or object.

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

      A customizable set of options.

    Options Hash (options):

    • :skip_status (Boolean, String, Integer)

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

    • :include_user_entities (Boolean, String, Integer)

      The user entities node will be disincluded when set to false.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



251
252
253
# File 'lib/twitter/rest/friends_and_followers.rb', line 251

def friends(*args)
  cursor_from_response_with_user(:users, Twitter::User, "/1.1/friends/list.json", args)
end

#friendship(source, target, options = {}) ⇒ Twitter::Relationship Also known as: friendship_show, relationship

Returns detailed information about the relationship between two users

Parameters:

  • source (Integer, String, Twitter::User)

    The Twitter user ID, screen name, or object of the source user.

  • target (Integer, String, Twitter::User)

    The Twitter user ID, screen name, or object of the target user.

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

    A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



182
183
184
185
186
187
188
189
# File 'lib/twitter/rest/friends_and_followers.rb', line 182

def friendship(source, target, options = {})
  options = options.dup
  merge_user!(options, source, "source")
  options[:source_id] = options.delete(:source_user_id) unless options[:source_user_id].nil?
  merge_user!(options, target, "target")
  options[:target_id] = options.delete(:target_user_id) unless options[:target_user_id].nil?
  perform_get_with_object("/1.1/friendships/show.json", options, Twitter::Relationship)
end

#friendship?(source, target, options = {}) ⇒ Boolean

Test for the existence of friendship between two users

Parameters:

  • source (Integer, String, Twitter::User)

    The Twitter user ID, screen name, or object of the source user.

  • target (Integer, String, Twitter::User)

    The Twitter user ID, screen name, or object of the target user.

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

    A customizable set of options.

Returns:

  • (Boolean)

    true if user_a follows user_b, otherwise false.

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



203
204
205
# File 'lib/twitter/rest/friends_and_followers.rb', line 203

def friendship?(source, target, options = {})
  friendship(source, target, options).source.following?
end

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

Allows one to enable or disable retweets and device notifications from the specified user.

Parameters:

  • user (Integer, String, Twitter::User)

    A Twitter user ID, screen name, URI, or object.

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

    A customizable set of options.

Options Hash (options):

  • :device (Boolean)

    Enable/disable device notifications from the target user.

  • :retweets (Boolean)

    Enable/disable retweets from the target user.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



167
168
169
170
# File 'lib/twitter/rest/friends_and_followers.rb', line 167

def friendship_update(user, options = {})
  merge_user!(options, user)
  perform_post_with_object("/1.1/friendships/update.json", options, Twitter::Relationship)
end

#friendships(*users) ⇒ Array<Twitter::User> #friendships(*users, options) ⇒ Array<Twitter::User>

Returns the relationship of the authenticating user to the comma separated list of up to 100 screen_names or user_ids provided. Values for connections can be: following, following_requested, followed_by, none.

Overloads:

  • #friendships(*users) ⇒ Array<Twitter::User>

    Parameters:

    • users (Enumerable<Integer, String, Twitter::User>)

      A collection of Twitter user IDs, screen names, or objects.

  • #friendships(*users, options) ⇒ Array<Twitter::User>

    Parameters:

    • users (Enumerable<Integer, String, Twitter::User>)

      A collection of Twitter user IDs, screen names, or objects.

    • options (Hash)

      A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



63
64
65
66
67
# File 'lib/twitter/rest/friends_and_followers.rb', line 63

def friendships(*args)
  arguments = Twitter::Arguments.new(args)
  merge_users!(arguments.options, arguments)
  perform_get_with_objects("/1.1/friendships/lookup.json", arguments.options, Twitter::User)
end

#friendships_incoming(options = {}) ⇒ Twitter::Cursor

Returns an array of numeric IDs for every user who has a pending request to follow the authenticating user

Parameters:

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

    A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



77
78
79
# File 'lib/twitter/rest/friends_and_followers.rb', line 77

def friendships_incoming(options = {})
  perform_get_with_cursor("/1.1/friendships/incoming.json", options, :ids)
end

#friendships_outgoing(options = {}) ⇒ Twitter::Cursor

Returns an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request

Parameters:

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

    A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



89
90
91
# File 'lib/twitter/rest/friends_and_followers.rb', line 89

def friendships_outgoing(options = {})
  perform_get_with_cursor("/1.1/friendships/outgoing.json", options, :ids)
end

#no_retweet_ids(options = {}) ⇒ Array<Integer> Also known as: no_retweets_ids

Returns a collection of user IDs that the currently authenticated user does not want to receive retweets from.

Parameters:

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

    A customizable set of options.

Returns:

  • (Array<Integer>)

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



263
264
265
# File 'lib/twitter/rest/friends_and_followers.rb', line 263

def no_retweet_ids(options = {})
  perform_get("/1.1/friendships/no_retweets/ids.json", options).collect(&:to_i)
end

#unfollow(*users) ⇒ Array<Twitter::User> #unfollow(*users, options) ⇒ Array<Twitter::User> Also known as: destroy_friendship

Allows the authenticating user to unfollow the specified users

Overloads:

  • #unfollow(*users) ⇒ Array<Twitter::User>

    Parameters:

    • users (Enumerable<Integer, String, Twitter::User>)

      A collection of Twitter user IDs, screen names, or objects.

  • #unfollow(*users, options) ⇒ Array<Twitter::User>

    Parameters:

    • users (Enumerable<Integer, String, Twitter::User>)

      A collection of Twitter user IDs, screen names, or objects.

    • options (Hash)

      A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



151
152
153
# File 'lib/twitter/rest/friends_and_followers.rb', line 151

def unfollow(*args)
  parallel_users_from_response(:post, "/1.1/friendships/destroy.json", args)
end