Module: Twitter::API::FriendsAndFollowers
Constant Summary
Constants included from Utils
Instance Method Summary collapse
-
#follow(*args) ⇒ Array<Twitter::User>
(also: #friendship_create)
Allows the authenticating user to follow the specified users, unless they are already followed.
-
#follow!(*args) ⇒ Array<Twitter::User>
(also: #friendship_create!)
Allows the authenticating user to follow the specified users.
- #follower_ids(*args) ⇒ Twitter::Cursor
-
#followers(*args) ⇒ Twitter::Cursor
Returns a cursored collection of user objects for users following the specified user.
- #friend_ids(*args) ⇒ Twitter::Cursor
-
#friends(*args) ⇒ Twitter::Cursor
(also: #following)
Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends").
-
#friendship(source, target, options = {}) ⇒ Twitter::Relationship
(also: #friendship_show, #relationship)
Returns detailed information about the relationship between two users.
-
#friendship?(source, target, options = {}) ⇒ Boolean
Test for the existence of friendship between two users.
-
#friendship_update(user, options = {}) ⇒ Twitter::Relationship
Allows one to enable or disable retweets and device notifications from the specified user.
-
#friendships(*args) ⇒ 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.
-
#friendships_incoming(options = {}) ⇒ Twitter::Cursor
Returns an array of numeric IDs for every user who has a pending request to follow the authenticating user.
-
#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.
-
#no_retweet_ids(options = {}) ⇒ Array<Integer>
(also: #no_retweets_ids)
Returns a collection of user_ids that the currently authenticated user does not want to receive retweets from.
-
#unfollow(*args) ⇒ Array<Twitter::User>
(also: #friendship_destroy)
Allows the authenticating user to unfollow the specified users.
Instance Method Details
#follow(*users) ⇒ Array<Twitter::User> #follow(*users, options) ⇒ Array<Twitter::User> Also known as: friendship_create
Allows the authenticating user to follow the specified users, unless they are already followed
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/twitter/api/friends_and_followers.rb', line 130 def follow(*args) arguments = Twitter::API::Arguments.new(args) # Twitter always turns on notifications if the "follow" option is present, even if it's set to false # so only send follow if it's true arguments.[:follow] = true if !!arguments..delete(:follow) existing_friends = Thread.new do friend_ids.ids end new_friends = Thread.new do users(args).map(&:id) end follow!(new_friends.value - existing_friends.value, arguments.) end |
#follow!(*users) ⇒ Array<Twitter::User> #follow!(*users, options) ⇒ Array<Twitter::User> Also known as: friendship_create!
Allows the authenticating user to follow the specified users
160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/twitter/api/friends_and_followers.rb', line 160 def follow!(*args) arguments = Twitter::API::Arguments.new(args) # Twitter always turns on notifications if the "follow" option is present, even if it's set to false # so only send follow if it's true arguments.[:follow] = true if !!arguments..delete(:follow) arguments.flatten.threaded_map do |user| begin object_from_response(Twitter::User, :post, "/1.1/friendships/create.json", merge_user(arguments., user)) rescue Twitter::Error::Forbidden # This error will be raised if the user doesn't have permission to # follow list_member, for whatever reason. end end.compact end |
#follower_ids(options = {}) ⇒ Twitter::Cursor #follower_ids(user, options = {}) ⇒ Twitter::Cursor
59 60 61 |
# File 'lib/twitter/api/friends_and_followers.rb', line 59 def follower_ids(*args) cursor_from_response_with_user(:ids, nil, :get, "/1.1/followers/ids.json", args, :follower_ids) end |
#friend_ids(options = {}) ⇒ Twitter::Cursor #friend_ids(user, options = {}) ⇒ Twitter::Cursor
Returns a cursored collection of user objects for users following the specified user.
282 283 284 |
# File 'lib/twitter/api/friends_and_followers.rb', line 282 def followers(*args) cursor_from_response_with_user(:users, Twitter::User, :get, "/1.1/followers/list.json", args, :followers) end |
#friend_ids(options = {}) ⇒ Twitter::Cursor #friend_ids(user, options = {}) ⇒ Twitter::Cursor
34 35 36 |
# File 'lib/twitter/api/friends_and_followers.rb', line 34 def friend_ids(*args) cursor_from_response_with_user(:ids, nil, :get, "/1.1/friends/ids.json", args, :friend_ids) end |
#friend_ids(options = {}) ⇒ Twitter::Cursor #friend_ids(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").
313 314 315 |
# File 'lib/twitter/api/friends_and_followers.rb', line 313 def friends(*args) cursor_from_response_with_user(:users, Twitter::User, :get, "/1.1/friends/list.json", args, :friends) end |
#friendship(source, target, options = {}) ⇒ Twitter::Relationship Also known as: friendship_show, relationship
Returns detailed information about the relationship between two users
227 228 229 230 231 232 233 |
# File 'lib/twitter/api/friends_and_followers.rb', line 227 def friendship(source, target, ={}) merge_user!(, source, "source") [:source_id] = .delete(:source_user_id) unless [:source_user_id].nil? merge_user!(, target, "target") [:target_id] = .delete(:target_user_id) unless [:target_user_id].nil? object_from_response(Twitter::Relationship, :get, "/1.1/friendships/show.json", ) end |
#friendship?(source, target, options = {}) ⇒ Boolean
Test for the existence of friendship between two users
251 252 253 |
# File 'lib/twitter/api/friends_and_followers.rb', line 251 def friendship?(source, target, ={}) friendship(source, target, ).source.following? end |
#friendship_update(user, options = {}) ⇒ Twitter::Relationship
Allows one to enable or disable retweets and device notifications from the specified user.
208 209 210 211 |
# File 'lib/twitter/api/friends_and_followers.rb', line 208 def friendship_update(user, ={}) merge_user!(, user) object_from_response(Twitter::Relationship, :post, "/1.1/friendships/update.json", ) 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.
79 80 81 82 83 |
# File 'lib/twitter/api/friends_and_followers.rb', line 79 def friendships(*args) arguments = Twitter::API::Arguments.new(args) merge_users!(arguments., arguments) objects_from_response(Twitter::User, :get, "/1.1/friendships/lookup.json", arguments.) 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
96 97 98 |
# File 'lib/twitter/api/friends_and_followers.rb', line 96 def friendships_incoming(={}) cursor_from_response(:ids, nil, :get, "/1.1/friendships/incoming.json", , :friendships_incoming) 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
111 112 113 |
# File 'lib/twitter/api/friends_and_followers.rb', line 111 def friendships_outgoing(={}) cursor_from_response(:ids, nil, :get, "/1.1/friendships/outgoing.json", , :friendships_outgoing) 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. =>
329 330 331 |
# File 'lib/twitter/api/friends_and_followers.rb', line 329 def no_retweet_ids(={}) get("/1.1/friendships/no_retweets/ids.json", )[:body].map(&:to_i) end |
#unfollow(*users) ⇒ Array<Twitter::User> #unfollow(*users, options) ⇒ Array<Twitter::User> Also known as: friendship_destroy
Allows the authenticating user to unfollow the specified users
190 191 192 |
# File 'lib/twitter/api/friends_and_followers.rb', line 190 def unfollow(*args) threaded_user_objects_from_response(:post, "/1.1/friendships/destroy.json", args) end |