Module: Twitter::REST::FriendsAndFollowers

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

Constant Summary

Constant Summary

Constants included from Utils

Utils::DEFAULT_CURSOR, Utils::URI_SUBSTRING

Instance Method Summary (collapse)

Methods included from Utils

flat_pmap, pmap

Instance Method Details

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

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

Overloads:

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

    Parameters:

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

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

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

    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

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

Allows the authenticating user to follow the specified users

Overloads:

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

    Parameters:

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

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

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

    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



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

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

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

Overloads:

  • - (Twitter::Cursor) follower_ids(options = {})

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

    Parameters:

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

      A customizable set of options.

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

    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, :get, '/1.1/followers/ids.json', args)
end

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

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

Overloads:

  • - (Twitter::Cursor) followers(options = {})

    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.

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

    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



229
230
231
# File 'lib/twitter/rest/friends_and_followers.rb', line 229

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

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

Overloads:

  • - (Twitter::Cursor) friend_ids(options = {})

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

    Parameters:

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

      A customizable set of options.

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

    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, :get, '/1.1/friends/ids.json', args)
end

- (Twitter::Cursor) friends(options = {}) - (Twitter::Cursor) friends(user, options = {}) 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:

  • - (Twitter::Cursor) friends(options = {})

    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.

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

    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



253
254
255
# File 'lib/twitter/rest/friends_and_followers.rb', line 253

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

- (Twitter::Relationship) friendship(source, target, options = {}) 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



185
186
187
188
189
190
191
# File 'lib/twitter/rest/friends_and_followers.rb', line 185

def friendship(source, target, options = {})
  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_with_object(:get, '/1.1/friendships/show.json', options, Twitter::Relationship)
end

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

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



205
206
207
# File 'lib/twitter/rest/friends_and_followers.rb', line 205

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

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

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



170
171
172
173
# File 'lib/twitter/rest/friends_and_followers.rb', line 170

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

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

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:

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

    Parameters:

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

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

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

    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_with_objects(:get, '/1.1/friendships/lookup.json', arguments.options, Twitter::User)
end

- (Twitter::Cursor) friendships_incoming(options = {})

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_with_cursor(:get, '/1.1/friendships/incoming.json', options, :ids)
end

- (Twitter::Cursor) friendships_outgoing(options = {})

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_with_cursor(:get, '/1.1/friendships/outgoing.json', options, :ids)
end

- (Array<Integer>) no_retweet_ids(options = {}) 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



265
266
267
# File 'lib/twitter/rest/friends_and_followers.rb', line 265

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

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

Allows the authenticating user to unfollow the specified users

Overloads:

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

    Parameters:

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

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

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

    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



153
154
155
# File 'lib/twitter/rest/friends_and_followers.rb', line 153

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