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

#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, options) ⇒ Array<Twitter::User>

    Options Hash (options):

    • :follow (Boolean) — default: false

      Enable notifications for the target user.

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, options) ⇒ Array<Twitter::User>

    Options Hash (options):

    • :follow (Boolean) — default: false

      Enable notifications for the target user.

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_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

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

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

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.

    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.

    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.

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, '/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

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

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

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").

    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").

    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.

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, '/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

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_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

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

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

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

Options Hash (options):

  • :device (Boolean)

    Enable/disable device notifications from the target user.

  • :retweets (Boolean)

    Enable/disable retweets from the target user.

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_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.

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

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

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.

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 = {})
  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

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