twitter 4.8.1 → 5.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG.md +30 -0
  3. data/LICENSE.md +1 -1
  4. data/README.md +386 -266
  5. data/lib/twitter.rb +4 -39
  6. data/lib/twitter/arguments.rb +11 -0
  7. data/lib/twitter/base.rb +89 -68
  8. data/lib/twitter/client.rb +69 -110
  9. data/lib/twitter/configuration.rb +7 -3
  10. data/lib/twitter/creatable.rb +2 -4
  11. data/lib/twitter/cursor.rb +50 -42
  12. data/lib/twitter/direct_message.rb +2 -11
  13. data/lib/twitter/entity/uri.rb +13 -0
  14. data/lib/twitter/enumerable.rb +15 -0
  15. data/lib/twitter/error.rb +55 -7
  16. data/lib/twitter/error/already_favorited.rb +1 -1
  17. data/lib/twitter/error/already_posted.rb +10 -0
  18. data/lib/twitter/error/already_retweeted.rb +1 -1
  19. data/lib/twitter/error/bad_gateway.rb +2 -3
  20. data/lib/twitter/error/bad_request.rb +2 -2
  21. data/lib/twitter/error/forbidden.rb +2 -2
  22. data/lib/twitter/error/gateway_timeout.rb +2 -3
  23. data/lib/twitter/error/internal_server_error.rb +2 -3
  24. data/lib/twitter/error/not_acceptable.rb +2 -2
  25. data/lib/twitter/error/not_found.rb +2 -2
  26. data/lib/twitter/error/service_unavailable.rb +2 -3
  27. data/lib/twitter/error/too_many_requests.rb +2 -2
  28. data/lib/twitter/error/unauthorized.rb +2 -2
  29. data/lib/twitter/error/unprocessable_entity.rb +2 -2
  30. data/lib/twitter/factory.rb +2 -8
  31. data/lib/twitter/geo_factory.rb +2 -2
  32. data/lib/twitter/geo_results.rb +36 -0
  33. data/lib/twitter/identity.rb +0 -22
  34. data/lib/twitter/list.rb +18 -4
  35. data/lib/twitter/media/photo.rb +3 -3
  36. data/lib/twitter/media_factory.rb +2 -2
  37. data/lib/twitter/null_object.rb +24 -0
  38. data/lib/twitter/oembed.rb +3 -2
  39. data/lib/twitter/place.rb +15 -9
  40. data/lib/twitter/profile_banner.rb +5 -3
  41. data/lib/twitter/rate_limit.rb +1 -17
  42. data/lib/twitter/relationship.rb +2 -10
  43. data/lib/twitter/rest/api/direct_messages.rb +135 -0
  44. data/lib/twitter/rest/api/favorites.rb +120 -0
  45. data/lib/twitter/rest/api/friends_and_followers.rb +290 -0
  46. data/lib/twitter/rest/api/help.rb +58 -0
  47. data/lib/twitter/rest/api/lists.rb +491 -0
  48. data/lib/twitter/rest/api/oauth.rb +45 -0
  49. data/lib/twitter/rest/api/places_and_geo.rb +104 -0
  50. data/lib/twitter/rest/api/saved_searches.rb +91 -0
  51. data/lib/twitter/rest/api/search.rb +37 -0
  52. data/lib/twitter/rest/api/spam_reporting.rb +29 -0
  53. data/lib/twitter/rest/api/suggested_users.rb +51 -0
  54. data/lib/twitter/rest/api/timelines.rb +202 -0
  55. data/lib/twitter/rest/api/trends.rb +58 -0
  56. data/lib/twitter/rest/api/tweets.rb +293 -0
  57. data/lib/twitter/rest/api/undocumented.rb +52 -0
  58. data/lib/twitter/rest/api/users.rb +383 -0
  59. data/lib/twitter/rest/api/utils.rb +219 -0
  60. data/lib/twitter/rest/client.rb +193 -0
  61. data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
  62. data/lib/twitter/rest/response/parse_json.rb +27 -0
  63. data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
  64. data/lib/twitter/search_results.rb +33 -21
  65. data/lib/twitter/settings.rb +1 -6
  66. data/lib/twitter/size.rb +1 -1
  67. data/lib/twitter/streaming/client.rb +77 -0
  68. data/lib/twitter/streaming/connection.rb +22 -0
  69. data/lib/twitter/streaming/response.rb +30 -0
  70. data/lib/twitter/suggestion.rb +4 -2
  71. data/lib/twitter/token.rb +8 -0
  72. data/lib/twitter/trend.rb +2 -1
  73. data/lib/twitter/trend_results.rb +59 -0
  74. data/lib/twitter/tweet.rb +41 -85
  75. data/lib/twitter/user.rb +51 -41
  76. data/lib/twitter/version.rb +4 -4
  77. data/spec/fixtures/already_posted.json +1 -0
  78. data/spec/fixtures/ids_list.json +1 -1
  79. data/spec/fixtures/ids_list2.json +1 -1
  80. data/spec/fixtures/search.json +1 -1
  81. data/spec/fixtures/search_malformed.json +1 -1
  82. data/spec/fixtures/track_streaming.json +3 -0
  83. data/spec/helper.rb +8 -13
  84. data/spec/twitter/base_spec.rb +25 -99
  85. data/spec/twitter/configuration_spec.rb +1 -1
  86. data/spec/twitter/cursor_spec.rb +13 -31
  87. data/spec/twitter/direct_message_spec.rb +41 -8
  88. data/spec/twitter/entity/uri_spec.rb +74 -0
  89. data/spec/twitter/error_spec.rb +59 -11
  90. data/spec/twitter/geo/point_spec.rb +1 -1
  91. data/spec/twitter/geo_factory_spec.rb +3 -3
  92. data/spec/twitter/geo_results_spec.rb +35 -0
  93. data/spec/twitter/identifiable_spec.rb +0 -21
  94. data/spec/twitter/list_spec.rb +51 -8
  95. data/spec/twitter/media/photo_spec.rb +118 -3
  96. data/spec/twitter/media_factory_spec.rb +2 -2
  97. data/spec/twitter/null_object_spec.rb +26 -0
  98. data/spec/twitter/oembed_spec.rb +69 -45
  99. data/spec/twitter/place_spec.rb +68 -12
  100. data/spec/twitter/profile_banner_spec.rb +1 -1
  101. data/spec/twitter/rate_limit_spec.rb +12 -12
  102. data/spec/twitter/relationship_spec.rb +31 -9
  103. data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +22 -9
  104. data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
  105. data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +104 -65
  106. data/spec/twitter/{api → rest/api}/geo_spec.rb +10 -10
  107. data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
  108. data/spec/twitter/{api → rest/api}/lists_spec.rb +77 -56
  109. data/spec/twitter/{api → rest/api}/oauth_spec.rb +6 -6
  110. data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +7 -7
  111. data/spec/twitter/{api → rest/api}/search_spec.rb +8 -9
  112. data/spec/twitter/{api → rest/api}/spam_reporting_spec.rb +3 -3
  113. data/spec/twitter/{api → rest/api}/suggested_users_spec.rb +5 -5
  114. data/spec/twitter/{api → rest/api}/timelines_spec.rb +9 -9
  115. data/spec/twitter/{api → rest/api}/trends_spec.rb +6 -6
  116. data/spec/twitter/rest/api/tweets_spec.rb +503 -0
  117. data/spec/twitter/{api → rest/api}/undocumented_spec.rb +19 -45
  118. data/spec/twitter/{api → rest/api}/users_spec.rb +60 -35
  119. data/spec/twitter/rest/client_spec.rb +193 -0
  120. data/spec/twitter/saved_search_spec.rb +11 -0
  121. data/spec/twitter/search_results_spec.rb +29 -42
  122. data/spec/twitter/settings_spec.rb +17 -6
  123. data/spec/twitter/streaming/client_spec.rb +75 -0
  124. data/spec/twitter/token_spec.rb +16 -0
  125. data/spec/twitter/trend_results_spec.rb +89 -0
  126. data/spec/twitter/trend_spec.rb +23 -0
  127. data/spec/twitter/tweet_spec.rb +122 -115
  128. data/spec/twitter/user_spec.rb +136 -77
  129. data/spec/twitter_spec.rb +0 -119
  130. data/twitter.gemspec +8 -5
  131. metadata +148 -141
  132. metadata.gz.sig +0 -0
  133. data/lib/twitter/action/favorite.rb +0 -19
  134. data/lib/twitter/action/follow.rb +0 -30
  135. data/lib/twitter/action/list_member_added.rb +0 -39
  136. data/lib/twitter/action/mention.rb +0 -46
  137. data/lib/twitter/action/reply.rb +0 -27
  138. data/lib/twitter/action/retweet.rb +0 -27
  139. data/lib/twitter/action/tweet.rb +0 -20
  140. data/lib/twitter/action_factory.rb +0 -22
  141. data/lib/twitter/api/arguments.rb +0 -13
  142. data/lib/twitter/api/direct_messages.rb +0 -148
  143. data/lib/twitter/api/favorites.rb +0 -126
  144. data/lib/twitter/api/friends_and_followers.rb +0 -334
  145. data/lib/twitter/api/help.rb +0 -64
  146. data/lib/twitter/api/lists.rb +0 -618
  147. data/lib/twitter/api/oauth.rb +0 -44
  148. data/lib/twitter/api/places_and_geo.rb +0 -121
  149. data/lib/twitter/api/saved_searches.rb +0 -99
  150. data/lib/twitter/api/search.rb +0 -37
  151. data/lib/twitter/api/spam_reporting.rb +0 -30
  152. data/lib/twitter/api/suggested_users.rb +0 -55
  153. data/lib/twitter/api/timelines.rb +0 -214
  154. data/lib/twitter/api/trends.rb +0 -63
  155. data/lib/twitter/api/tweets.rb +0 -304
  156. data/lib/twitter/api/undocumented.rb +0 -97
  157. data/lib/twitter/api/users.rb +0 -439
  158. data/lib/twitter/api/utils.rb +0 -187
  159. data/lib/twitter/configurable.rb +0 -96
  160. data/lib/twitter/default.rb +0 -102
  161. data/lib/twitter/entity/url.rb +0 -9
  162. data/lib/twitter/error/client_error.rb +0 -35
  163. data/lib/twitter/error/decode_error.rb +0 -9
  164. data/lib/twitter/error/identity_map_key_error.rb +0 -9
  165. data/lib/twitter/error/server_error.rb +0 -28
  166. data/lib/twitter/exceptable.rb +0 -36
  167. data/lib/twitter/identity_map.rb +0 -22
  168. data/lib/twitter/request/multipart_with_file.rb +0 -34
  169. data/lib/twitter/response/parse_json.rb +0 -25
  170. data/spec/fixtures/about_me.json +0 -1
  171. data/spec/fixtures/activity_summary.json +0 -1
  172. data/spec/fixtures/bad_gateway.json +0 -1
  173. data/spec/fixtures/bad_request.json +0 -1
  174. data/spec/fixtures/by_friends.json +0 -1
  175. data/spec/fixtures/end_session.json +0 -1
  176. data/spec/fixtures/forbidden.json +0 -1
  177. data/spec/fixtures/internal_server_error.json +0 -1
  178. data/spec/fixtures/not_acceptable.json +0 -1
  179. data/spec/fixtures/phoenix_search.phoenix +0 -1
  180. data/spec/fixtures/resolve.json +0 -1
  181. data/spec/fixtures/service_unavailable.json +0 -1
  182. data/spec/fixtures/totals.json +0 -1
  183. data/spec/fixtures/trends.json +0 -1
  184. data/spec/fixtures/unauthorized.json +0 -1
  185. data/spec/fixtures/video_facets.json +0 -1
  186. data/spec/twitter/action/favorite_spec.rb +0 -29
  187. data/spec/twitter/action/follow_spec.rb +0 -29
  188. data/spec/twitter/action/list_member_added_spec.rb +0 -41
  189. data/spec/twitter/action/mention_spec.rb +0 -52
  190. data/spec/twitter/action/reply_spec.rb +0 -41
  191. data/spec/twitter/action/retweet_spec.rb +0 -41
  192. data/spec/twitter/action_factory_spec.rb +0 -35
  193. data/spec/twitter/action_spec.rb +0 -16
  194. data/spec/twitter/api/tweets_spec.rb +0 -285
  195. data/spec/twitter/client_spec.rb +0 -223
  196. data/spec/twitter/error/client_error_spec.rb +0 -23
  197. data/spec/twitter/error/server_error_spec.rb +0 -20
@@ -1,334 +0,0 @@
1
- require 'twitter/api/arguments'
2
- require 'twitter/api/utils'
3
- require 'twitter/cursor'
4
- require 'twitter/error/forbidden'
5
- require 'twitter/relationship'
6
- require 'twitter/user'
7
-
8
- module Twitter
9
- module API
10
- module FriendsAndFollowers
11
- include Twitter::API::Utils
12
-
13
- # @see https://dev.twitter.com/docs/api/1.1/get/friends/ids
14
- # @rate_limited Yes
15
- # @authentication Requires user context
16
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
17
- # @return [Twitter::Cursor]
18
- # @overload friend_ids(options={})
19
- # Returns an array of numeric IDs for every user the authenticated user is following
20
- #
21
- # @param options [Hash] A customizable set of options.
22
- # @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list.
23
- # @example Return the authenticated user's friends' IDs
24
- # Twitter.friend_ids
25
- # @overload friend_ids(user, options={})
26
- # Returns an array of numeric IDs for every user the specified user is following
27
- #
28
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
29
- # @param options [Hash] A customizable set of options.
30
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
31
- # @example Return @sferik's friends' IDs
32
- # Twitter.friend_ids('sferik')
33
- # Twitter.friend_ids(7505382) # Same as above
34
- def friend_ids(*args)
35
- cursor_from_response_with_user(:ids, nil, :get, "/1.1/friends/ids.json", args, :friend_ids)
36
- end
37
-
38
- # @see https://dev.twitter.com/docs/api/1.1/get/followers/ids
39
- # @rate_limited Yes
40
- # @authentication Requires user context
41
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
42
- # @return [Twitter::Cursor]
43
- # @overload follower_ids(options={})
44
- # Returns an array of numeric IDs for every user following the authenticated user
45
- #
46
- # @param options [Hash] A customizable set of options.
47
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
48
- # @example Return the authenticated user's followers' IDs
49
- # Twitter.follower_ids
50
- # @overload follower_ids(user, options={})
51
- # Returns an array of numeric IDs for every user following the specified user
52
- #
53
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
54
- # @param options [Hash] A customizable set of options.
55
- # @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list.
56
- # @example Return @sferik's followers' IDs
57
- # Twitter.follower_ids('sferik')
58
- # Twitter.follower_ids(7505382) # Same as above
59
- def follower_ids(*args)
60
- cursor_from_response_with_user(:ids, nil, :get, "/1.1/followers/ids.json", args, :follower_ids)
61
- end
62
-
63
- # 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.
64
- #
65
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/lookup
66
- # @rate_limited Yes
67
- # @authentication Requires user context
68
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
69
- # @return [Array<Twitter::User>] The requested users.
70
- # @overload friendships(*users)
71
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
72
- # @example Return extended information for @sferik and @pengwynn
73
- # Twitter.friendships('sferik', 'pengwynn')
74
- # Twitter.friendships('sferik', 14100886) # Same as above
75
- # Twitter.friendships(7505382, 14100886) # Same as above
76
- # @overload friendships(*users, options)
77
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
78
- # @param options [Hash] A customizable set of options.
79
- def friendships(*args)
80
- arguments = Twitter::API::Arguments.new(args)
81
- merge_users!(arguments.options, arguments)
82
- objects_from_response(Twitter::User, :get, "/1.1/friendships/lookup.json", arguments.options)
83
- end
84
-
85
- # Returns an array of numeric IDs for every user who has a pending request to follow the authenticating user
86
- #
87
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/incoming
88
- # @rate_limited Yes
89
- # @authentication Requires user context
90
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
91
- # @return [Twitter::Cursor]
92
- # @param options [Hash] A customizable set of options.
93
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
94
- # @example Return an array of numeric IDs for every user who has a pending request to follow the authenticating user
95
- # Twitter.friendships_incoming
96
- def friendships_incoming(options={})
97
- cursor_from_response(:ids, nil, :get, "/1.1/friendships/incoming.json", options, :friendships_incoming)
98
- end
99
-
100
- # Returns an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request
101
- #
102
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/outgoing
103
- # @rate_limited Yes
104
- # @authentication Requires user context
105
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
106
- # @return [Twitter::Cursor]
107
- # @param options [Hash] A customizable set of options.
108
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
109
- # @example Return an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request
110
- # Twitter.friendships_outgoing
111
- def friendships_outgoing(options={})
112
- cursor_from_response(:ids, nil, :get, "/1.1/friendships/outgoing.json", options, :friendships_outgoing)
113
- end
114
-
115
- # Allows the authenticating user to follow the specified users, unless they are already followed
116
- #
117
- # @see https://dev.twitter.com/docs/api/1.1/post/friendships/create
118
- # @rate_limited Yes
119
- # @authentication Requires user context
120
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
121
- # @return [Array<Twitter::User>] The followed users.
122
- # @overload follow(*users)
123
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
124
- # @example Follow @sferik
125
- # Twitter.follow('sferik')
126
- # @overload follow(*users, options)
127
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
128
- # @param options [Hash] A customizable set of options.
129
- # @option options [Boolean] :follow (false) Enable notifications for the target user.
130
- def follow(*args)
131
- arguments = Twitter::API::Arguments.new(args)
132
- # Twitter always turns on notifications if the "follow" option is present, even if it's set to false
133
- # so only send follow if it's true
134
- arguments.options[:follow] = true if !!arguments.options.delete(:follow)
135
- existing_friends = Thread.new do
136
- friend_ids.ids
137
- end
138
- new_friends = Thread.new do
139
- users(args).map(&:id)
140
- end
141
- follow!(new_friends.value - existing_friends.value, arguments.options)
142
- end
143
- alias friendship_create follow
144
-
145
- # Allows the authenticating user to follow the specified users
146
- #
147
- # @see https://dev.twitter.com/docs/api/1.1/post/friendships/create
148
- # @rate_limited No
149
- # @authentication Requires user context
150
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
151
- # @return [Array<Twitter::User>] The followed users.
152
- # @overload follow!(*users)
153
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
154
- # @example Follow @sferik
155
- # Twitter.follow!('sferik')
156
- # @overload follow!(*users, options)
157
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
158
- # @param options [Hash] A customizable set of options.
159
- # @option options [Boolean] :follow (false) Enable notifications for the target user.
160
- def follow!(*args)
161
- arguments = Twitter::API::Arguments.new(args)
162
- # Twitter always turns on notifications if the "follow" option is present, even if it's set to false
163
- # so only send follow if it's true
164
- arguments.options[:follow] = true if !!arguments.options.delete(:follow)
165
- arguments.flatten.threaded_map do |user|
166
- begin
167
- object_from_response(Twitter::User, :post, "/1.1/friendships/create.json", merge_user(arguments.options, user))
168
- rescue Twitter::Error::Forbidden
169
- # This error will be raised if the user doesn't have permission to
170
- # follow list_member, for whatever reason.
171
- end
172
- end.compact
173
- end
174
- alias friendship_create! follow!
175
-
176
- # Allows the authenticating user to unfollow the specified users
177
- #
178
- # @see https://dev.twitter.com/docs/api/1.1/post/friendships/destroy
179
- # @rate_limited No
180
- # @authentication Requires user context
181
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
182
- # @return [Array<Twitter::User>] The unfollowed users.
183
- # @overload unfollow(*users)
184
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
185
- # @example Unfollow @sferik
186
- # Twitter.unfollow('sferik')
187
- # @overload unfollow(*users, options)
188
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
189
- # @param options [Hash] A customizable set of options.
190
- def unfollow(*args)
191
- threaded_user_objects_from_response(:post, "/1.1/friendships/destroy.json", args)
192
- end
193
- alias friendship_destroy unfollow
194
-
195
- # Allows one to enable or disable retweets and device notifications from the specified user.
196
- #
197
- # @see https://dev.twitter.com/docs/api/1.1/post/friendships/update
198
- # @rate_limited No
199
- # @authentication Requires user context
200
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
201
- # @return [Twitter::Relationship]
202
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
203
- # @param options [Hash] A customizable set of options.
204
- # @option options [Boolean] :device Enable/disable device notifications from the target user.
205
- # @option options [Boolean] :retweets Enable/disable retweets from the target user.
206
- # @example Enable rewteets and devise notifications for @sferik
207
- # Twitter.friendship_update('sferik', :device => true, :retweets => true)
208
- def friendship_update(user, options={})
209
- merge_user!(options, user)
210
- object_from_response(Twitter::Relationship, :post, "/1.1/friendships/update.json", options)
211
- end
212
-
213
- # Returns detailed information about the relationship between two users
214
- #
215
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/show
216
- # @rate_limited Yes
217
- # @authentication Requires user context
218
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
219
- # @return [Twitter::Relationship]
220
- # @param source [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the source user.
221
- # @param target [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the target user.
222
- # @param options [Hash] A customizable set of options.
223
- # @example Return the relationship between @sferik and @pengwynn
224
- # Twitter.friendship('sferik', 'pengwynn')
225
- # Twitter.friendship('sferik', 14100886) # Same as above
226
- # Twitter.friendship(7505382, 14100886) # Same as above
227
- def friendship(source, target, options={})
228
- merge_user!(options, source, "source")
229
- options[:source_id] = options.delete(:source_user_id) unless options[:source_user_id].nil?
230
- merge_user!(options, target, "target")
231
- options[:target_id] = options.delete(:target_user_id) unless options[:target_user_id].nil?
232
- object_from_response(Twitter::Relationship, :get, "/1.1/friendships/show.json", options)
233
- end
234
- alias friendship_show friendship
235
- alias relationship friendship
236
-
237
- # Test for the existence of friendship between two users
238
- #
239
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/show
240
- # @rate_limited Yes
241
- # @authentication Requires user context
242
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
243
- # @return [Boolean] true if user_a follows user_b, otherwise false.
244
- # @param source [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the source user.
245
- # @param target [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the target user.
246
- # @param options [Hash] A customizable set of options.
247
- # @example Return true if @sferik follows @pengwynn
248
- # Twitter.friendship?('sferik', 'pengwynn')
249
- # Twitter.friendship?('sferik', 14100886) # Same as above
250
- # Twitter.friendship?(7505382, 14100886) # Same as above
251
- def friendship?(source, target, options={})
252
- friendship(source, target, options).source.following?
253
- end
254
-
255
- # Returns a cursored collection of user objects for users following the specified user.
256
- #
257
- # @see https://dev.twitter.com/docs/api/1.1/get/followers/list
258
- # @rate_limited Yes
259
- # @authentication Requires user context
260
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
261
- # @return [Twitter::Cursor]
262
- # @overload followers(options={})
263
- # Returns a cursored collection of user objects for users following the authenticated user.
264
- #
265
- # @param options [Hash] A customizable set of options.
266
- # @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list.
267
- # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
268
- # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
269
- # @example Return the authenticated user's friends' IDs
270
- # Twitter.followers
271
- # @overload followers(user, options={})
272
- # Returns a cursored collection of user objects for users following the specified user.
273
- #
274
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
275
- # @param options [Hash] A customizable set of options.
276
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
277
- # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
278
- # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
279
- # @example Return the cursored collection of users following @sferik
280
- # Twitter.followers('sferik')
281
- # Twitter.followers(7505382) # Same as above
282
- def followers(*args)
283
- cursor_from_response_with_user(:users, Twitter::User, :get, "/1.1/followers/list.json", args, :followers)
284
- end
285
-
286
- # Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends").
287
- #
288
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/show
289
- # @rate_limited Yes
290
- # @authentication Requires user context
291
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
292
- # @return [Twitter::Cursor]
293
- # @overload friends(options={})
294
- # Returns a cursored collection of user objects for every user the authenticated user is following (otherwise known as their "friends").
295
- #
296
- # @param options [Hash] A customizable set of options.
297
- # @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list.
298
- # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
299
- # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
300
- # @example Return the authenticated user's friends' IDs
301
- # Twitter.friends
302
- # @overload friends(user, options={})
303
- # Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends").
304
- #
305
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
306
- # @param options [Hash] A customizable set of options.
307
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
308
- # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
309
- # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
310
- # @example Return the cursored collection of users @sferik is following
311
- # Twitter.friends('sferik')
312
- # Twitter.friends(7505382) # Same as above
313
- def friends(*args)
314
- cursor_from_response_with_user(:users, Twitter::User, :get, "/1.1/friends/list.json", args, :friends)
315
- end
316
- alias following friends
317
-
318
- # Returns a collection of user IDs that the currently authenticated user does not want to receive retweets from.
319
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/no_retweets/ids
320
- # @rate_limited Yes
321
- # @authentication Requires user context
322
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
323
- # @return [Array<Integer>]
324
- # @param options [Hash] A customizable set of options.
325
- # @example Return a collection of user IDs that the currently authenticated user does not want to receive retweets from
326
- # Twitter.no_retweet_ids
327
- def no_retweet_ids(options={})
328
- get("/1.1/friendships/no_retweets/ids.json", options)[:body].map(&:to_i)
329
- end
330
- alias no_retweets_ids no_retweet_ids
331
-
332
- end
333
- end
334
- end
@@ -1,64 +0,0 @@
1
- require 'twitter/api/utils'
2
- require 'twitter/configuration'
3
- require 'twitter/language'
4
-
5
- module Twitter
6
- module API
7
- module Help
8
- include Twitter::API::Utils
9
-
10
- # Returns the current configuration used by Twitter
11
- #
12
- # @see https://dev.twitter.com/docs/api/1.1/get/help/configuration
13
- # @rate_limited Yes
14
- # @authentication Requires user context
15
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
16
- # @return [Twitter::Configuration] Twitter's configuration.
17
- # @example Return the current configuration used by Twitter
18
- # Twitter.configuration
19
- def configuration(options={})
20
- object_from_response(Twitter::Configuration, :get, "/1.1/help/configuration.json", options)
21
- end
22
-
23
- # Returns the list of languages supported by Twitter
24
- #
25
- # @see https://dev.twitter.com/docs/api/1.1/get/help/languages
26
- # @rate_limited Yes
27
- # @authentication Requires user context
28
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
29
- # @return [Array<Twitter::Language>]
30
- # @example Return the list of languages Twitter supports
31
- # Twitter.languages
32
- def languages(options={})
33
- objects_from_response(Twitter::Language, :get, "/1.1/help/languages.json", options)
34
- end
35
-
36
- # Returns {https://twitter.com/privacy Twitter's Privacy Policy}
37
- #
38
- # @see https://dev.twitter.com/docs/api/1.1/get/help/privacy
39
- # @rate_limited Yes
40
- # @authentication Requires user context
41
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
42
- # @return [String]
43
- # @example Return {https://twitter.com/privacy Twitter's Privacy Policy}
44
- # Twitter.privacy
45
- def privacy(options={})
46
- get("/1.1/help/privacy.json", options)[:body][:privacy]
47
- end
48
-
49
- # Returns {https://twitter.com/tos Twitter's Terms of Service}
50
- #
51
- # @see https://dev.twitter.com/docs/api/1.1/get/help/tos
52
- # @rate_limited Yes
53
- # @authentication Requires user context
54
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
55
- # @return [String]
56
- # @example Return {https://twitter.com/tos Twitter's Terms of Service}
57
- # Twitter.tos
58
- def tos(options={})
59
- get("/1.1/help/tos.json", options)[:body][:tos]
60
- end
61
-
62
- end
63
- end
64
- end
@@ -1,618 +0,0 @@
1
- require 'twitter/api/arguments'
2
- require 'twitter/api/utils'
3
- require 'twitter/core_ext/enumerable'
4
- require 'twitter/cursor'
5
- require 'twitter/error/forbidden'
6
- require 'twitter/error/not_found'
7
- require 'twitter/list'
8
- require 'twitter/tweet'
9
- require 'twitter/user'
10
-
11
- module Twitter
12
- module API
13
- module Lists
14
- include Twitter::API::Utils
15
- MAX_USERS_PER_REQUEST = 100
16
-
17
- # Returns all lists the authenticating or specified user subscribes to, including their own
18
- #
19
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/list
20
- # @rate_limited Yes
21
- # @authentication Requires user context
22
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
23
- # @return [Array<Twitter::List>]
24
- # @overload lists(options={})
25
- # @param options [Hash] A customizable set of options.
26
- # @option options [Boolean] :reverse Set this to true if you would like owned lists to be returned first.
27
- # @example Return all lists the authenticating user subscribes to
28
- # Twitter.lists
29
- # @overload lists(user, options={})
30
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
31
- # @param options [Hash] A customizable set of options.
32
- # @option options [Boolean] :reverse Set this to true if you would like owned lists to be returned first.
33
- # @example Return all lists that @sferik subscribes to
34
- # Twitter.lists('sferik')
35
- # Twitter.lists(7505382)
36
- def lists(*args)
37
- objects_from_response_with_user(Twitter::List, :get, "/1.1/lists/list.json", args)
38
- end
39
- alias lists_subscribed_to lists
40
-
41
- # Show tweet timeline for members of the specified list
42
- #
43
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/statuses
44
- # @rate_limited Yes
45
- # @authentication Requires user context
46
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
47
- # @return [Array<Twitter::Tweet>]
48
- # @overload list_timeline(list, options={})
49
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
50
- # @param options [Hash] A customizable set of options.
51
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
52
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
53
- # @option options [Integer] :count The number of results to retrieve.
54
- # @example Show tweet timeline for members of the authenticated user's "presidents" list
55
- # Twitter.list_timeline('presidents')
56
- # Twitter.list_timeline(8863586)
57
- # @overload list_timeline(user, list, options={})
58
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
59
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
60
- # @param options [Hash] A customizable set of options.
61
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
62
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
63
- # @option options [Integer] :count The number of results to retrieve.
64
- # @example Show tweet timeline for members of @sferik's "presidents" list
65
- # Twitter.list_timeline('sferik', 'presidents')
66
- # Twitter.list_timeline('sferik', 8863586)
67
- # Twitter.list_timeline(7505382, 'presidents')
68
- # Twitter.list_timeline(7505382, 8863586)
69
- def list_timeline(*args)
70
- arguments = Twitter::API::Arguments.new(args)
71
- merge_list!(arguments.options, arguments.pop)
72
- merge_owner!(arguments.options, arguments.pop)
73
- objects_from_response(Twitter::Tweet, :get, "/1.1/lists/statuses.json", arguments.options)
74
- end
75
-
76
- # Removes the specified member from the list
77
- #
78
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy
79
- # @rate_limited No
80
- # @authentication Requires user context
81
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
82
- # @return [Twitter::List] The list.
83
- # @overload list_remove_member(list, user_to_remove, options={})
84
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
85
- # @param user_to_remove [Integer, String] The user id or screen name of the list member to remove.
86
- # @param options [Hash] A customizable set of options.
87
- # @example Remove @BarackObama from the authenticated user's "presidents" list
88
- # Twitter.list_remove_member('presidents', 813286)
89
- # Twitter.list_remove_member('presidents', 'BarackObama')
90
- # Twitter.list_remove_member(8863586, 'BarackObama')
91
- # @overload list_remove_member(user, list, user_to_remove, options={})
92
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
93
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
94
- # @param user_to_remove [Integer, String] The user id or screen name of the list member to remove.
95
- # @param options [Hash] A customizable set of options.
96
- # @example Remove @BarackObama from @sferik's "presidents" list
97
- # Twitter.list_remove_member('sferik', 'presidents', 813286)
98
- # Twitter.list_remove_member('sferik', 'presidents', 'BarackObama')
99
- # Twitter.list_remove_member('sferik', 8863586, 'BarackObama')
100
- # Twitter.list_remove_member(7505382, 'presidents', 813286)
101
- def list_remove_member(*args)
102
- list_from_response_with_user(:post, "/1.1/lists/members/destroy.json", args)
103
- end
104
-
105
- # List the lists the specified user has been added to
106
- #
107
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/memberships
108
- # @rate_limited Yes
109
- # @authentication Requires user context
110
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
111
- # @return [Twitter::Cursor]
112
- # @overload memberships(options={})
113
- # @param options [Hash] A customizable set of options.
114
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
115
- # @option options [Boolean, String, Integer] :filter_to_owned_lists When set to true, t or 1, will return just lists the authenticating user owns, and the user represented by user_id or screen_name is a member of.
116
- # @example List the lists the authenticated user has been added to
117
- # Twitter.memberships
118
- # @overload memberships(user, options={})
119
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
120
- # @param options [Hash] A customizable set of options.
121
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
122
- # @option options [Boolean, String, Integer] :filter_to_owned_lists When set to true, t or 1, will return just lists the authenticating user owns, and the user represented by user_id or screen_name is a member of.
123
- # @example List the lists that @sferik has been added to
124
- # Twitter.memberships('sferik')
125
- # Twitter.memberships(7505382)
126
- def memberships(*args)
127
- cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/memberships.json", args, :memberships)
128
- end
129
-
130
- # Returns the subscribers of the specified list
131
- #
132
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscribers
133
- # @rate_limited Yes
134
- # @authentication Requires user context
135
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
136
- # @return [Twitter::Cursor] The subscribers of the specified list.
137
- # @overload list_subscribers(list, options={})
138
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
139
- # @param options [Hash] A customizable set of options.
140
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
141
- # @example Return the subscribers of the authenticated user's "presidents" list
142
- # Twitter.list_subscribers('presidents')
143
- # Twitter.list_subscribers(8863586)
144
- # @overload list_subscribers(user, list, options={})
145
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
146
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
147
- # @param options [Hash] A customizable set of options.
148
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
149
- # @example Return the subscribers of @sferik's "presidents" list
150
- # Twitter.list_subscribers('sferik', 'presidents')
151
- # Twitter.list_subscribers('sferik', 8863586)
152
- # Twitter.list_subscribers(7505382, 'presidents')
153
- def list_subscribers(*args)
154
- cursor_from_response_with_list(:get, "/1.1/lists/subscribers.json", args, :list_subscribers)
155
- end
156
-
157
- # Make the authenticated user follow the specified list
158
- #
159
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/create
160
- # @rate_limited No
161
- # @authentication Requires user context
162
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
163
- # @return [Twitter::List] The specified list.
164
- # @overload list_subscribe(list, options={})
165
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
166
- # @param options [Hash] A customizable set of options.
167
- # @example Subscribe to the authenticated user's "presidents" list
168
- # Twitter.list_subscribe('presidents')
169
- # Twitter.list_subscribe(8863586)
170
- # @overload list_subscribe(user, list, options={})
171
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
172
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
173
- # @param options [Hash] A customizable set of options.
174
- # @example Subscribe to @sferik's "presidents" list
175
- # Twitter.list_subscribe('sferik', 'presidents')
176
- # Twitter.list_subscribe('sferik', 8863586)
177
- # Twitter.list_subscribe(7505382, 'presidents')
178
- def list_subscribe(*args)
179
- list_from_response(:post, "/1.1/lists/subscribers/create.json", args)
180
- end
181
-
182
- # Check if a user is a subscriber of the specified list
183
- #
184
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscribers/show
185
- # @rate_limited Yes
186
- # @authentication Requires user context
187
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
188
- # @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
189
- # @overload list_subscriber?(list, user_to_check, options={})
190
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
191
- # @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
192
- # @param options [Hash] A customizable set of options.
193
- # @example Check if @BarackObama is a subscriber of the authenticated user's "presidents" list
194
- # Twitter.list_subscriber?('presidents', 813286)
195
- # Twitter.list_subscriber?(8863586, 813286)
196
- # Twitter.list_subscriber?('presidents', 'BarackObama')
197
- # @overload list_subscriber?(user, list, user_to_check, options={})
198
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
199
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
200
- # @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
201
- # @param options [Hash] A customizable set of options.
202
- # @example Check if @BarackObama is a subscriber of @sferik's "presidents" list
203
- # Twitter.list_subscriber?('sferik', 'presidents', 813286)
204
- # Twitter.list_subscriber?('sferik', 8863586, 813286)
205
- # Twitter.list_subscriber?(7505382, 'presidents', 813286)
206
- # Twitter.list_subscriber?('sferik', 'presidents', 'BarackObama')
207
- # @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
208
- def list_subscriber?(*args)
209
- list_user?(:get, "/1.1/lists/subscribers/show.json", args)
210
- end
211
-
212
- # Unsubscribes the authenticated user form the specified list
213
- #
214
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/destroy
215
- # @rate_limited No
216
- # @authentication Requires user context
217
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
218
- # @return [Twitter::List] The specified list.
219
- # @overload list_unsubscribe(list, options={})
220
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
221
- # @param options [Hash] A customizable set of options.
222
- # @example Unsubscribe from the authenticated user's "presidents" list
223
- # Twitter.list_unsubscribe('presidents')
224
- # Twitter.list_unsubscribe(8863586)
225
- # @overload list_unsubscribe(user, list, options={})
226
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
227
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
228
- # @param options [Hash] A customizable set of options.
229
- # @example Unsubscribe from @sferik's "presidents" list
230
- # Twitter.list_unsubscribe('sferik', 'presidents')
231
- # Twitter.list_unsubscribe('sferik', 8863586)
232
- # Twitter.list_unsubscribe(7505382, 'presidents')
233
- def list_unsubscribe(*args)
234
- list_from_response(:post, "/1.1/lists/subscribers/destroy.json", args)
235
- end
236
-
237
- # Adds specified members to a list
238
- #
239
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/create_all
240
- # @note Lists are limited to having 500 members, and you are limited to adding up to 100 members to a list at a time with this method.
241
- # @rate_limited No
242
- # @authentication Requires user context
243
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
244
- # @return [Twitter::List] The list.
245
- # @overload list_add_members(list, users, options={})
246
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
247
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
248
- # @param options [Hash] A customizable set of options.
249
- # @example Add @BarackObama and @pengwynn to the authenticated user's "presidents" list
250
- # Twitter.list_add_members('presidents', ['BarackObama', 'pengwynn'])
251
- # Twitter.list_add_members('presidents', [813286, 18755393])
252
- # Twitter.list_add_members(8863586, ['BarackObama', 'pengwynn'])
253
- # Twitter.list_add_members(8863586, [813286, 18755393])
254
- # @overload list_add_members(user, list, users, options={})
255
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
256
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
257
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
258
- # @param options [Hash] A customizable set of options.
259
- # @example Add @BarackObama and @pengwynn to @sferik's "presidents" list
260
- # Twitter.list_add_members('sferik', 'presidents', ['BarackObama', 'pengwynn'])
261
- # Twitter.list_add_members('sferik', 'presidents', [813286, 18755393])
262
- # Twitter.list_add_members(7505382, 'presidents', ['BarackObama', 'pengwynn'])
263
- # Twitter.list_add_members(7505382, 'presidents', [813286, 18755393])
264
- # Twitter.list_add_members(7505382, 8863586, ['BarackObama', 'pengwynn'])
265
- # Twitter.list_add_members(7505382, 8863586, [813286, 18755393])
266
- def list_add_members(*args)
267
- list_from_response_with_users(:post, "/1.1/lists/members/create_all.json", args)
268
- end
269
-
270
- # Check if a user is a member of the specified list
271
- #
272
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/members/show
273
- # @authentication Requires user context
274
- # @rate_limited Yes
275
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
276
- # @return [Boolean] true if user is a member of the specified list, otherwise false.
277
- # @overload list_member?(list, user_to_check, options={})
278
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
279
- # @param user_to_check [Integer, String] The user ID or screen name of the list member.
280
- # @param options [Hash] A customizable set of options.
281
- # @example Check if @BarackObama is a member of the authenticated user's "presidents" list
282
- # Twitter.list_member?('presidents', 813286)
283
- # Twitter.list_member?(8863586, 'BarackObama')
284
- # @overload list_member?(user, list, user_to_check, options={})
285
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
286
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
287
- # @param user_to_check [Integer, String] The user ID or screen name of the list member.
288
- # @param options [Hash] A customizable set of options.
289
- # @example Check if @BarackObama is a member of @sferik's "presidents" list
290
- # Twitter.list_member?('sferik', 'presidents', 813286)
291
- # Twitter.list_member?('sferik', 8863586, 'BarackObama')
292
- # Twitter.list_member?(7505382, 'presidents', 813286)
293
- def list_member?(*args)
294
- list_user?(:get, "/1.1/lists/members/show.json", args)
295
- end
296
-
297
- # Returns the members of the specified list
298
- #
299
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/members
300
- # @rate_limited Yes
301
- # @authentication Requires user context
302
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
303
- # @return [Twitter::Cursor]
304
- # @overload list_members(list, options={})
305
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
306
- # @param options [Hash] A customizable set of options.
307
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
308
- # @example Return the members of the authenticated user's "presidents" list
309
- # Twitter.list_members('presidents')
310
- # Twitter.list_members(8863586)
311
- # @overload list_members(user, list, options={})
312
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
313
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
314
- # @param options [Hash] A customizable set of options.
315
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
316
- # @example Return the members of @sferik's "presidents" list
317
- # Twitter.list_members('sferik', 'presidents')
318
- # Twitter.list_members('sferik', 8863586)
319
- # Twitter.list_members(7505382, 'presidents')
320
- # Twitter.list_members(7505382, 8863586)
321
- def list_members(*args)
322
- cursor_from_response_with_list(:get, "/1.1/lists/members.json", args, :list_members)
323
- end
324
-
325
- # Add a member to a list
326
- #
327
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/create
328
- # @note Lists are limited to having 500 members.
329
- # @rate_limited No
330
- # @authentication Requires user context
331
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
332
- # @return [Twitter::List] The list.
333
- # @overload list_add_member(list, user_to_add, options={})
334
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
335
- # @param user_to_add [Integer, String] The user id or screen name to add to the list.
336
- # @param options [Hash] A customizable set of options.
337
- # @example Add @BarackObama to the authenticated user's "presidents" list
338
- # Twitter.list_add_member('presidents', 813286)
339
- # Twitter.list_add_member(8863586, 813286)
340
- # @overload list_add_member(user, list, user_to_add, options={})
341
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
342
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
343
- # @param user_to_add [Integer, String] The user id or screen name to add to the list.
344
- # @param options [Hash] A customizable set of options.
345
- # @example Add @BarackObama to @sferik's "presidents" list
346
- # Twitter.list_add_member('sferik', 'presidents', 813286)
347
- # Twitter.list_add_member('sferik', 8863586, 813286)
348
- # Twitter.list_add_member(7505382, 'presidents', 813286)
349
- # Twitter.list_add_member(7505382, 8863586, 813286)
350
- def list_add_member(*args)
351
- list_from_response_with_user(:post, "/1.1/lists/members/create.json", args)
352
- end
353
-
354
- # Deletes the specified list
355
- #
356
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/destroy
357
- # @note Must be owned by the authenticated user.
358
- # @rate_limited No
359
- # @authentication Requires user context
360
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
361
- # @return [Twitter::List] The deleted list.
362
- # @overload list_destroy(list, options={})
363
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
364
- # @param options [Hash] A customizable set of options.
365
- # @example Delete the authenticated user's "presidents" list
366
- # Twitter.list_destroy('presidents')
367
- # Twitter.list_destroy(8863586)
368
- # @overload list_destroy(user, list, options={})
369
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
370
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
371
- # @param options [Hash] A customizable set of options.
372
- # @example Delete @sferik's "presidents" list
373
- # Twitter.list_destroy('sferik', 'presidents')
374
- # Twitter.list_destroy('sferik', 8863586)
375
- # Twitter.list_destroy(7505382, 'presidents')
376
- # Twitter.list_destroy(7505382, 8863586)
377
- def list_destroy(*args)
378
- list_from_response(:post, "/1.1/lists/destroy.json", args)
379
- end
380
-
381
- # Updates the specified list
382
- #
383
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/update
384
- # @rate_limited No
385
- # @authentication Requires user context
386
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
387
- # @return [Twitter::List] The created list.
388
- # @overload list_update(list, options={})
389
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
390
- # @param options [Hash] A customizable set of options.
391
- # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
392
- # @option options [String] :description The description to give the list.
393
- # @example Update the authenticated user's "presidents" list to have the description "Presidents of the United States of America"
394
- # Twitter.list_update('presidents', :description => "Presidents of the United States of America")
395
- # Twitter.list_update(8863586, :description => "Presidents of the United States of America")
396
- # @overload list_update(user, list, options={})
397
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
398
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
399
- # @param options [Hash] A customizable set of options.
400
- # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
401
- # @option options [String] :description The description to give the list.
402
- # @example Update the @sferik's "presidents" list to have the description "Presidents of the United States of America"
403
- # Twitter.list_update('sferik', 'presidents', :description => "Presidents of the United States of America")
404
- # Twitter.list_update(7505382, 'presidents', :description => "Presidents of the United States of America")
405
- # Twitter.list_update('sferik', 8863586, :description => "Presidents of the United States of America")
406
- # Twitter.list_update(7505382, 8863586, :description => "Presidents of the United States of America")
407
- def list_update(*args)
408
- list_from_response(:post, "/1.1/lists/update.json", args)
409
- end
410
-
411
- # Creates a new list for the authenticated user
412
- #
413
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/create
414
- # @note Accounts are limited to 20 lists.
415
- # @rate_limited No
416
- # @authentication Requires user context
417
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
418
- # @return [Twitter::List] The created list.
419
- # @param name [String] The name for the list.
420
- # @param options [Hash] A customizable set of options.
421
- # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
422
- # @option options [String] :description The description to give the list.
423
- # @example Create a list named 'presidents'
424
- # Twitter.list_create('presidents')
425
- def list_create(name, options={})
426
- object_from_response(Twitter::List, :post, "/1.1/lists/create.json", options.merge(:name => name))
427
- end
428
-
429
- # Show the specified list
430
- #
431
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/show
432
- # @note Private lists will only be shown if the authenticated user owns the specified list.
433
- # @rate_limited Yes
434
- # @authentication Requires user context
435
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
436
- # @return [Twitter::List] The specified list.
437
- # @overload list(list, options={})
438
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
439
- # @param options [Hash] A customizable set of options.
440
- # @example Show the authenticated user's "presidents" list
441
- # Twitter.list('presidents')
442
- # Twitter.list(8863586)
443
- # @overload list(user, list, options={})
444
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
445
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
446
- # @param options [Hash] A customizable set of options.
447
- # @example Show @sferik's "presidents" list
448
- # Twitter.list('sferik', 'presidents')
449
- # Twitter.list('sferik', 8863586)
450
- # Twitter.list(7505382, 'presidents')
451
- # Twitter.list(7505382, 8863586)
452
- def list(*args)
453
- list_from_response(:get, "/1.1/lists/show.json", args)
454
- end
455
-
456
- # List the lists the specified user follows
457
- #
458
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscriptions
459
- # @rate_limited Yes
460
- # @authentication Requires user context
461
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
462
- # @return [Twitter::Cursor]
463
- # @overload subscriptions(options={})
464
- # @param options [Hash] A customizable set of options.
465
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
466
- # @example List the lists the authenticated user follows
467
- # Twitter.subscriptions
468
- # @overload subscriptions(user, options={})
469
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
470
- # @param options [Hash] A customizable set of options.
471
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
472
- # @example List the lists that @sferik follows
473
- # Twitter.subscriptions('sferik')
474
- # Twitter.subscriptions(7505382)
475
- def subscriptions(*args)
476
- cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/subscriptions.json", args, :subscriptions)
477
- end
478
-
479
- # Removes specified members from the list
480
- #
481
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy_all
482
- # @rate_limited No
483
- # @authentication Requires user context
484
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
485
- # @return [Twitter::List] The list.
486
- # @overload list_remove_members(list, users, options={})
487
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
488
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
489
- # @param options [Hash] A customizable set of options.
490
- # @example Remove @BarackObama and @pengwynn from the authenticated user's "presidents" list
491
- # Twitter.list_remove_members('presidents', ['BarackObama', 'pengwynn'])
492
- # Twitter.list_remove_members('presidents', [813286, 18755393])
493
- # Twitter.list_remove_members(8863586, ['BarackObama', 'pengwynn'])
494
- # Twitter.list_remove_members(8863586, [813286, 18755393])
495
- # @overload list_remove_members(user, list, users, options={})
496
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
497
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
498
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
499
- # @param options [Hash] A customizable set of options.
500
- # @example Remove @BarackObama and @pengwynn from @sferik's "presidents" list
501
- # Twitter.list_remove_members('sferik', 'presidents', ['BarackObama', 'pengwynn'])
502
- # Twitter.list_remove_members('sferik', 'presidents', [813286, 18755393])
503
- # Twitter.list_remove_members(7505382, 'presidents', ['BarackObama', 'pengwynn'])
504
- # Twitter.list_remove_members(7505382, 'presidents', [813286, 18755393])
505
- # Twitter.list_remove_members(7505382, 8863586, ['BarackObama', 'pengwynn'])
506
- # Twitter.list_remove_members(7505382, 8863586, [813286, 18755393])
507
- def list_remove_members(*args)
508
- list_from_response_with_users(:post, "/1.1/lists/members/destroy_all.json", args)
509
- end
510
-
511
- # Returns the lists owned by the specified Twitter user
512
- #
513
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/ownerships
514
- # @rate_limited Yes
515
- # @authentication Requires user context
516
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
517
- # @return [Array<Twitter::List>]
518
- # @overload lists_owned(options={})
519
- # @param options [Hash] A customizable set of options.
520
- # @option options [Integer] :count The amount of results to return per page. Defaults to 20. No more than 1000 results will ever be returned in a single page.
521
- # @example Return all lists the authenticating user owns
522
- # Twitter.lists_owend
523
- # @overload lists_owned(user, options={})
524
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
525
- # @param options [Hash] A customizable set of options.
526
- # @option options [Integer] :count The amount of results to return per page. Defaults to 20. No more than 1000 results will ever be returned in a single page.
527
- # @example Return all lists that @sferik owns
528
- # Twitter.lists_owned('sferik')
529
- # Twitter.lists_owned(7505382)
530
- def lists_owned(*args)
531
- cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/ownerships.json", args, :lists_owned)
532
- end
533
- alias lists_ownerships lists_owned
534
-
535
- private
536
-
537
- # @param request_method [Symbol]
538
- # @param path [String]
539
- # @param args [Array]
540
- # @return [Array<Twitter::User>]
541
- def list_from_response(request_method, path, args)
542
- arguments = Twitter::API::Arguments.new(args)
543
- merge_list!(arguments.options, arguments.pop)
544
- merge_owner!(arguments.options, arguments.pop)
545
- object_from_response(Twitter::List, request_method, path, arguments.options)
546
- end
547
-
548
- def cursor_from_response_with_list(request_method, path, args, calling_method)
549
- arguments = Twitter::API::Arguments.new(args)
550
- merge_list!(arguments.options, arguments.pop)
551
- merge_owner!(arguments.options, arguments.pop)
552
- cursor_from_response(:users, Twitter::User, request_method, path, arguments.options, calling_method)
553
- end
554
-
555
- def list_user?(request_method, path, args)
556
- arguments = Twitter::API::Arguments.new(args)
557
- merge_user!(arguments.options, arguments.pop)
558
- merge_list!(arguments.options, arguments.pop)
559
- merge_owner!(arguments.options, arguments.pop)
560
- send(request_method.to_sym, path, arguments.options)
561
- true
562
- rescue Twitter::Error::NotFound, Twitter::Error::Forbidden
563
- false
564
- end
565
-
566
- def list_from_response_with_user(request_method, path, args)
567
- arguments = Twitter::API::Arguments.new(args)
568
- merge_user!(arguments.options, arguments.pop)
569
- merge_list!(arguments.options, arguments.pop)
570
- merge_owner!(arguments.options, arguments.pop)
571
- object_from_response(Twitter::List, request_method, path, arguments.options)
572
- end
573
-
574
- def list_from_response_with_users(request_method, path, args)
575
- arguments = Twitter::API::Arguments.new(args)
576
- members = arguments.pop
577
- merge_list!(arguments.options, arguments.pop)
578
- merge_owner!(arguments.options, arguments.pop)
579
- members.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
580
- object_from_response(Twitter::List, request_method, path, merge_users(arguments.options, users))
581
- end.last
582
- end
583
-
584
- # Take a list and merge it into the hash with the correct key
585
- #
586
- # @param hash [Hash]
587
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
588
- # @return [Hash]
589
- def merge_list!(hash, list)
590
- case list
591
- when Integer
592
- hash[:list_id] = list
593
- when String
594
- hash[:slug] = list
595
- when Twitter::List
596
- hash[:list_id] = list.id
597
- merge_owner!(hash, list.user)
598
- end
599
- hash
600
- end
601
-
602
- # Take an owner and merge it into the hash with the correct key
603
- #
604
- # @param hash [Hash]
605
- # @param user[Integer, String, Twitter::User] A Twitter user ID, screen_name, or object.
606
- # @return [Hash]
607
- def merge_owner!(hash, user)
608
- unless hash[:owner_id] || hash[:owner_screen_name]
609
- user ||= screen_name
610
- merge_user!(hash, user, "owner")
611
- hash[:owner_id] = hash.delete(:owner_user_id) unless hash[:owner_user_id].nil?
612
- end
613
- hash
614
- end
615
-
616
- end
617
- end
618
- end