twitter 5.6.0 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.yardopts +1 -0
  3. data/CHANGELOG.md +8 -0
  4. data/README.md +3 -3
  5. data/Rakefile +1 -1
  6. data/lib/twitter/base.rb +0 -8
  7. data/lib/twitter/client.rb +2 -1
  8. data/lib/twitter/cursor.rb +2 -15
  9. data/lib/twitter/error.rb +90 -18
  10. data/lib/twitter/geo_results.rb +0 -10
  11. data/lib/twitter/request.rb +4 -4
  12. data/lib/twitter/rest/api.rb +43 -0
  13. data/lib/twitter/rest/client.rb +10 -44
  14. data/lib/twitter/rest/direct_messages.rb +138 -0
  15. data/lib/twitter/rest/favorites.rb +108 -0
  16. data/lib/twitter/rest/friends_and_followers.rb +281 -0
  17. data/lib/twitter/rest/help.rb +56 -0
  18. data/lib/twitter/rest/lists.rb +497 -0
  19. data/lib/twitter/rest/oauth.rb +65 -0
  20. data/lib/twitter/rest/places_and_geo.rb +84 -0
  21. data/lib/twitter/rest/request/multipart_with_file.rb +5 -5
  22. data/lib/twitter/rest/response/parse_json.rb +2 -4
  23. data/lib/twitter/rest/response/raise_error.rb +24 -15
  24. data/lib/twitter/rest/saved_searches.rb +93 -0
  25. data/lib/twitter/rest/search.rb +37 -0
  26. data/lib/twitter/rest/spam_reporting.rb +27 -0
  27. data/lib/twitter/rest/suggested_users.rb +49 -0
  28. data/lib/twitter/rest/timelines.rb +200 -0
  29. data/lib/twitter/rest/trends.rb +57 -0
  30. data/lib/twitter/rest/tweets.rb +309 -0
  31. data/lib/twitter/rest/undocumented.rb +49 -0
  32. data/lib/twitter/rest/users.rb +383 -0
  33. data/lib/twitter/rest/utils.rb +205 -0
  34. data/lib/twitter/search_results.rb +2 -13
  35. data/lib/twitter/trend_results.rb +0 -10
  36. data/lib/twitter/version.rb +1 -1
  37. data/spec/helper.rb +1 -1
  38. data/spec/twitter/error_spec.rb +26 -42
  39. data/spec/twitter/rest/{api/direct_messages_spec.rb → direct_messages_spec.rb} +1 -1
  40. data/spec/twitter/rest/{api/favorites_spec.rb → favorites_spec.rb} +1 -1
  41. data/spec/twitter/rest/{api/friends_and_followers_spec.rb → friends_and_followers_spec.rb} +1 -1
  42. data/spec/twitter/rest/{api/geo_spec.rb → geo_spec.rb} +1 -1
  43. data/spec/twitter/rest/{api/help_spec.rb → help_spec.rb} +1 -1
  44. data/spec/twitter/rest/{api/lists_spec.rb → lists_spec.rb} +1 -1
  45. data/spec/twitter/rest/{api/oauth_spec.rb → oauth_spec.rb} +4 -8
  46. data/spec/twitter/rest/{api/saved_searches_spec.rb → saved_searches_spec.rb} +1 -1
  47. data/spec/twitter/rest/{api/search_spec.rb → search_spec.rb} +1 -1
  48. data/spec/twitter/rest/{api/spam_reporting_spec.rb → spam_reporting_spec.rb} +1 -1
  49. data/spec/twitter/rest/{api/suggested_users_spec.rb → suggested_users_spec.rb} +1 -1
  50. data/spec/twitter/rest/{api/timelines_spec.rb → timelines_spec.rb} +1 -1
  51. data/spec/twitter/rest/{api/trends_spec.rb → trends_spec.rb} +1 -1
  52. data/spec/twitter/rest/{api/tweets_spec.rb → tweets_spec.rb} +74 -5
  53. data/spec/twitter/rest/{api/undocumented_spec.rb → undocumented_spec.rb} +1 -1
  54. data/spec/twitter/rest/{api/users_spec.rb → users_spec.rb} +5 -5
  55. data/spec/twitter/tweet_spec.rb +1 -1
  56. data/twitter.gemspec +0 -1
  57. metadata +247 -237
  58. metadata.gz.sig +0 -0
  59. checksums.yaml +0 -7
  60. checksums.yaml.gz.sig +0 -0
  61. data/lib/twitter/error/already_favorited.rb +0 -10
  62. data/lib/twitter/error/already_posted.rb +0 -10
  63. data/lib/twitter/error/already_retweeted.rb +0 -10
  64. data/lib/twitter/error/bad_gateway.rb +0 -10
  65. data/lib/twitter/error/bad_request.rb +0 -10
  66. data/lib/twitter/error/configuration_error.rb +0 -8
  67. data/lib/twitter/error/forbidden.rb +0 -10
  68. data/lib/twitter/error/gateway_timeout.rb +0 -10
  69. data/lib/twitter/error/internal_server_error.rb +0 -10
  70. data/lib/twitter/error/not_acceptable.rb +0 -10
  71. data/lib/twitter/error/not_found.rb +0 -10
  72. data/lib/twitter/error/request_timeout.rb +0 -10
  73. data/lib/twitter/error/service_unavailable.rb +0 -10
  74. data/lib/twitter/error/too_many_requests.rb +0 -12
  75. data/lib/twitter/error/unauthorized.rb +0 -10
  76. data/lib/twitter/error/unprocessable_entity.rb +0 -10
  77. data/lib/twitter/rest/api/direct_messages.rb +0 -140
  78. data/lib/twitter/rest/api/favorites.rb +0 -115
  79. data/lib/twitter/rest/api/friends_and_followers.rb +0 -284
  80. data/lib/twitter/rest/api/help.rb +0 -58
  81. data/lib/twitter/rest/api/lists.rb +0 -500
  82. data/lib/twitter/rest/api/oauth.rb +0 -67
  83. data/lib/twitter/rest/api/places_and_geo.rb +0 -86
  84. data/lib/twitter/rest/api/saved_searches.rb +0 -95
  85. data/lib/twitter/rest/api/search.rb +0 -39
  86. data/lib/twitter/rest/api/spam_reporting.rb +0 -29
  87. data/lib/twitter/rest/api/suggested_users.rb +0 -51
  88. data/lib/twitter/rest/api/timelines.rb +0 -202
  89. data/lib/twitter/rest/api/trends.rb +0 -58
  90. data/lib/twitter/rest/api/tweets.rb +0 -297
  91. data/lib/twitter/rest/api/undocumented.rb +0 -51
  92. data/lib/twitter/rest/api/users.rb +0 -383
  93. data/lib/twitter/rest/api/utils.rb +0 -212
@@ -0,0 +1,56 @@
1
+ require 'twitter/configuration'
2
+ require 'twitter/language'
3
+ require 'twitter/request'
4
+ require 'twitter/rest/utils'
5
+
6
+ module Twitter
7
+ module REST
8
+ module Help
9
+ include Twitter::REST::Utils
10
+
11
+ # Returns the current configuration used by Twitter
12
+ #
13
+ # @see https://dev.twitter.com/docs/api/1.1/get/help/configuration
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::Configuration] Twitter's configuration.
18
+ def configuration(options = {})
19
+ perform_with_object(:get, '/1.1/help/configuration.json', options, Twitter::Configuration)
20
+ end
21
+
22
+ # Returns the list of languages supported by Twitter
23
+ #
24
+ # @see https://dev.twitter.com/docs/api/1.1/get/help/languages
25
+ # @rate_limited Yes
26
+ # @authentication Requires user context
27
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
28
+ # @return [Array<Twitter::Language>]
29
+ def languages(options = {})
30
+ perform_with_objects(:get, '/1.1/help/languages.json', options, Twitter::Language)
31
+ end
32
+
33
+ # Returns {https://twitter.com/privacy Twitter's Privacy Policy}
34
+ #
35
+ # @see https://dev.twitter.com/docs/api/1.1/get/help/privacy
36
+ # @rate_limited Yes
37
+ # @authentication Requires user context
38
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
39
+ # @return [String]
40
+ def privacy(options = {})
41
+ get('/1.1/help/privacy.json', options).body[:privacy]
42
+ end
43
+
44
+ # Returns {https://twitter.com/tos Twitter's Terms of Service}
45
+ #
46
+ # @see https://dev.twitter.com/docs/api/1.1/get/help/tos
47
+ # @rate_limited Yes
48
+ # @authentication Requires user context
49
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
50
+ # @return [String]
51
+ def tos(options = {})
52
+ get('/1.1/help/tos.json', options).body[:tos]
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,497 @@
1
+ require 'twitter/arguments'
2
+ require 'twitter/cursor'
3
+ require 'twitter/error'
4
+ require 'twitter/list'
5
+ require 'twitter/request'
6
+ require 'twitter/rest/utils'
7
+ require 'twitter/tweet'
8
+ require 'twitter/user'
9
+ require 'twitter/utils'
10
+
11
+ module Twitter
12
+ module REST
13
+ module Lists
14
+ include Twitter::REST::Utils
15
+ include Twitter::Utils
16
+ MAX_USERS_PER_REQUEST = 100
17
+ URI_SUBSTRING = '://'
18
+
19
+ # Returns all lists the authenticating or specified user subscribes to, including their own
20
+ #
21
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/list
22
+ # @rate_limited Yes
23
+ # @authentication Requires user context
24
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
25
+ # @return [Array<Twitter::List>]
26
+ # @overload lists(options = {})
27
+ # @param options [Hash] A customizable set of options.
28
+ # @option options [Boolean] :reverse Set this to true if you would like owned lists to be returned first.
29
+ # @overload lists(user, options = {})
30
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, 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
+ def lists(*args)
34
+ objects_from_response_with_user(Twitter::List, :get, '/1.1/lists/list.json', args)
35
+ end
36
+ alias_method :lists_subscribed_to, :lists
37
+
38
+ # Show tweet timeline for members of the specified list
39
+ #
40
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/statuses
41
+ # @rate_limited Yes
42
+ # @authentication Requires user context
43
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
44
+ # @return [Array<Twitter::Tweet>]
45
+ # @overload list_timeline(list, options = {})
46
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
47
+ # @param options [Hash] A customizable set of options.
48
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
49
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
50
+ # @option options [Integer] :count The number of results to retrieve.
51
+ # @overload list_timeline(user, list, options = {})
52
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
53
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
54
+ # @param options [Hash] A customizable set of options.
55
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
56
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
57
+ # @option options [Integer] :count The number of results to retrieve.
58
+ def list_timeline(*args)
59
+ arguments = Twitter::Arguments.new(args)
60
+ merge_list!(arguments.options, arguments.pop)
61
+ merge_owner!(arguments.options, arguments.pop)
62
+ perform_with_objects(:get, '/1.1/lists/statuses.json', arguments.options, Twitter::Tweet)
63
+ end
64
+
65
+ # Removes the specified member from the list
66
+ #
67
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy
68
+ # @rate_limited No
69
+ # @authentication Requires user context
70
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
71
+ # @return [Twitter::List] The list.
72
+ # @overload remove_list_member(list, user_to_remove, options = {})
73
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
74
+ # @param user_to_remove [Integer, String] The user id or screen name of the list member to remove.
75
+ # @param options [Hash] A customizable set of options.
76
+ # @overload remove_list_member(user, list, user_to_remove, options = {})
77
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
78
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
79
+ # @param user_to_remove [Integer, String] The user id or screen name of the list member to remove.
80
+ # @param options [Hash] A customizable set of options.
81
+ def remove_list_member(*args)
82
+ list_from_response_with_user(:post, '/1.1/lists/members/destroy.json', args)
83
+ end
84
+ deprecate_alias :list_remove_member, :remove_list_member
85
+
86
+ # List the lists the specified user has been added to
87
+ #
88
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/memberships
89
+ # @rate_limited Yes
90
+ # @authentication Requires user context
91
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
92
+ # @return [Twitter::Cursor]
93
+ # @overload memberships(options = {})
94
+ # @param options [Hash] A customizable set of options.
95
+ # @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.
96
+ # @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.
97
+ # @overload memberships(user, options = {})
98
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
99
+ # @param options [Hash] A customizable set of options.
100
+ # @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.
101
+ # @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.
102
+ def memberships(*args)
103
+ cursor_from_response_with_user(:lists, Twitter::List, :get, '/1.1/lists/memberships.json', args)
104
+ end
105
+
106
+ # Returns the subscribers of the specified list
107
+ #
108
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscribers
109
+ # @rate_limited Yes
110
+ # @authentication Requires user context
111
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
112
+ # @return [Twitter::Cursor] The subscribers of the specified list.
113
+ # @overload list_subscribers(list, options = {})
114
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
115
+ # @param options [Hash] A customizable set of options.
116
+ # @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.
117
+ # @overload list_subscribers(user, list, options = {})
118
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
119
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, 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
+ def list_subscribers(*args)
123
+ cursor_from_response_with_list(:get, '/1.1/lists/subscribers.json', args)
124
+ end
125
+
126
+ # Make the authenticated user follow the specified list
127
+ #
128
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/create
129
+ # @rate_limited No
130
+ # @authentication Requires user context
131
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
132
+ # @return [Twitter::List] The specified list.
133
+ # @overload list_subscribe(list, options = {})
134
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
135
+ # @param options [Hash] A customizable set of options.
136
+ # @overload list_subscribe(user, list, options = {})
137
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
138
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
139
+ # @param options [Hash] A customizable set of options.
140
+ def list_subscribe(*args)
141
+ list_from_response(:post, '/1.1/lists/subscribers/create.json', args)
142
+ end
143
+
144
+ # Check if a user is a subscriber of the specified list
145
+ #
146
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscribers/show
147
+ # @rate_limited Yes
148
+ # @authentication Requires user context
149
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
150
+ # @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
151
+ # @overload list_subscriber?(list, user_to_check, options = {})
152
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
153
+ # @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
154
+ # @param options [Hash] A customizable set of options.
155
+ # @overload list_subscriber?(user, list, user_to_check, options = {})
156
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
157
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
158
+ # @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
159
+ # @param options [Hash] A customizable set of options.
160
+ # @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
161
+ def list_subscriber?(*args)
162
+ list_user?(:get, '/1.1/lists/subscribers/show.json', args)
163
+ end
164
+
165
+ # Unsubscribes the authenticated user form the specified list
166
+ #
167
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/destroy
168
+ # @rate_limited No
169
+ # @authentication Requires user context
170
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
171
+ # @return [Twitter::List] The specified list.
172
+ # @overload list_unsubscribe(list, options = {})
173
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
174
+ # @param options [Hash] A customizable set of options.
175
+ # @overload list_unsubscribe(user, list, options = {})
176
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
177
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
178
+ # @param options [Hash] A customizable set of options.
179
+ def list_unsubscribe(*args)
180
+ list_from_response(:post, '/1.1/lists/subscribers/destroy.json', args)
181
+ end
182
+
183
+ # Adds specified members to a list
184
+ #
185
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/create_all
186
+ # @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.
187
+ # @rate_limited No
188
+ # @authentication Requires user context
189
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
190
+ # @return [Twitter::List] The list.
191
+ # @overload add_list_members(list, users, options = {})
192
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
193
+ # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
194
+ # @param options [Hash] A customizable set of options.
195
+ # @overload add_list_members(user, list, users, options = {})
196
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
197
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
198
+ # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
199
+ # @param options [Hash] A customizable set of options.
200
+ def add_list_members(*args)
201
+ list_from_response_with_users(:post, '/1.1/lists/members/create_all.json', args)
202
+ end
203
+ deprecate_alias :list_add_members, :add_list_members
204
+
205
+ # Check if a user is a member of the specified list
206
+ #
207
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/members/show
208
+ # @authentication Requires user context
209
+ # @rate_limited Yes
210
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
211
+ # @return [Boolean] true if user is a member of the specified list, otherwise false.
212
+ # @overload list_member?(list, user_to_check, options = {})
213
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
214
+ # @param user_to_check [Integer, String] The user ID or screen name of the list member.
215
+ # @param options [Hash] A customizable set of options.
216
+ # @overload list_member?(user, list, user_to_check, options = {})
217
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
218
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
219
+ # @param user_to_check [Integer, String] The user ID or screen name of the list member.
220
+ # @param options [Hash] A customizable set of options.
221
+ def list_member?(*args)
222
+ list_user?(:get, '/1.1/lists/members/show.json', args)
223
+ end
224
+
225
+ # Returns the members of the specified list
226
+ #
227
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/members
228
+ # @rate_limited Yes
229
+ # @authentication Requires user context
230
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
231
+ # @return [Twitter::Cursor]
232
+ # @overload list_members(list, options = {})
233
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
234
+ # @param options [Hash] A customizable set of options.
235
+ # @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.
236
+ # @overload list_members(user, list, options = {})
237
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
238
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
239
+ # @param options [Hash] A customizable set of options.
240
+ # @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.
241
+ def list_members(*args)
242
+ cursor_from_response_with_list(:get, '/1.1/lists/members.json', args)
243
+ end
244
+
245
+ # Add a member to a list
246
+ #
247
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/create
248
+ # @note Lists are limited to having 500 members.
249
+ # @rate_limited No
250
+ # @authentication Requires user context
251
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
252
+ # @return [Twitter::List] The list.
253
+ # @overload add_list_member(list, user_to_add, options = {})
254
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
255
+ # @param user_to_add [Integer, String] The user id or screen name to add to the list.
256
+ # @param options [Hash] A customizable set of options.
257
+ # @overload add_list_member(user, list, user_to_add, options = {})
258
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
259
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
260
+ # @param user_to_add [Integer, String] The user id or screen name to add to the list.
261
+ # @param options [Hash] A customizable set of options.
262
+ def add_list_member(*args)
263
+ list_from_response_with_user(:post, '/1.1/lists/members/create.json', args)
264
+ end
265
+ deprecate_alias :list_add_member, :add_list_member
266
+
267
+ # Deletes the specified list
268
+ #
269
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/destroy
270
+ # @note Must be owned by the authenticated user.
271
+ # @rate_limited No
272
+ # @authentication Requires user context
273
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
274
+ # @return [Twitter::List] The deleted list.
275
+ # @overload destroy_list(list, options = {})
276
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
277
+ # @param options [Hash] A customizable set of options.
278
+ # @overload destroy_list(user, list, options = {})
279
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
280
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
281
+ # @param options [Hash] A customizable set of options.
282
+ def destroy_list(*args)
283
+ list_from_response(:post, '/1.1/lists/destroy.json', args)
284
+ end
285
+ deprecate_alias :list_destroy, :destroy_list
286
+
287
+ # Updates the specified list
288
+ #
289
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/update
290
+ # @rate_limited No
291
+ # @authentication Requires user context
292
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
293
+ # @return [Twitter::List] The created list.
294
+ # @overload list_update(list, options = {})
295
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
296
+ # @param options [Hash] A customizable set of options.
297
+ # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
298
+ # @option options [String] :description The description to give the list.
299
+ # @overload list_update(user, list, options = {})
300
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
301
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
302
+ # @param options [Hash] A customizable set of options.
303
+ # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
304
+ # @option options [String] :description The description to give the list.
305
+ def list_update(*args)
306
+ list_from_response(:post, '/1.1/lists/update.json', args)
307
+ end
308
+
309
+ # Creates a new list for the authenticated user
310
+ #
311
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/create
312
+ # @note Accounts are limited to 20 lists.
313
+ # @rate_limited No
314
+ # @authentication Requires user context
315
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
316
+ # @return [Twitter::List] The created list.
317
+ # @param name [String] The name for the list.
318
+ # @param options [Hash] A customizable set of options.
319
+ # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
320
+ # @option options [String] :description The description to give the list.
321
+ def create_list(name, options = {})
322
+ perform_with_object(:post, '/1.1/lists/create.json', options.merge(:name => name), Twitter::List)
323
+ end
324
+ deprecate_alias :list_create, :create_list
325
+
326
+ # Show the specified list
327
+ #
328
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/show
329
+ # @note Private lists will only be shown if the authenticated user owns the specified list.
330
+ # @rate_limited Yes
331
+ # @authentication Requires user context
332
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
333
+ # @return [Twitter::List] The specified list.
334
+ # @overload list(list, options = {})
335
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
336
+ # @param options [Hash] A customizable set of options.
337
+ # @overload list(user, list, options = {})
338
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
339
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
340
+ # @param options [Hash] A customizable set of options.
341
+ def list(*args)
342
+ list_from_response(:get, '/1.1/lists/show.json', args)
343
+ end
344
+
345
+ # List the lists the specified user follows
346
+ #
347
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscriptions
348
+ # @rate_limited Yes
349
+ # @authentication Requires user context
350
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
351
+ # @return [Twitter::Cursor]
352
+ # @overload subscriptions(options = {})
353
+ # @param options [Hash] A customizable set of options.
354
+ # @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.
355
+ # @overload subscriptions(user, options = {})
356
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
357
+ # @param options [Hash] A customizable set of options.
358
+ # @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.
359
+ def subscriptions(*args)
360
+ cursor_from_response_with_user(:lists, Twitter::List, :get, '/1.1/lists/subscriptions.json', args)
361
+ end
362
+
363
+ # Removes specified members from the list
364
+ #
365
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy_all
366
+ # @rate_limited No
367
+ # @authentication Requires user context
368
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
369
+ # @return [Twitter::List] The list.
370
+ # @overload remove_list_members(list, users, options = {})
371
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
372
+ # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
373
+ # @param options [Hash] A customizable set of options.
374
+ # @overload remove_list_members(user, list, users, options = {})
375
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
376
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
377
+ # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
378
+ # @param options [Hash] A customizable set of options.
379
+ def remove_list_members(*args)
380
+ list_from_response_with_users(:post, '/1.1/lists/members/destroy_all.json', args)
381
+ end
382
+ deprecate_alias :list_remove_members, :remove_list_members
383
+
384
+ # Returns the lists owned by the specified Twitter user
385
+ #
386
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/ownerships
387
+ # @rate_limited Yes
388
+ # @authentication Requires user context
389
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
390
+ # @return [Array<Twitter::List>]
391
+ # @overload owned_lists(options = {})
392
+ # @param options [Hash] A customizable set of options.
393
+ # @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.
394
+ # @overload owned_lists(user, options = {})
395
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
396
+ # @param options [Hash] A customizable set of options.
397
+ # @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.
398
+ def owned_lists(*args)
399
+ cursor_from_response_with_user(:lists, Twitter::List, :get, '/1.1/lists/ownerships.json', args)
400
+ end
401
+ deprecate_alias :lists_ownerships, :owned_lists
402
+ deprecate_alias :lists_owned, :owned_lists
403
+
404
+ private
405
+
406
+ # @param request_method [Symbol]
407
+ # @param path [String]
408
+ # @param args [Array]
409
+ # @return [Array<Twitter::User>]
410
+ def list_from_response(request_method, path, args)
411
+ arguments = Twitter::Arguments.new(args)
412
+ merge_list!(arguments.options, arguments.pop)
413
+ merge_owner!(arguments.options, arguments.pop)
414
+ perform_with_object(request_method, path, arguments.options, Twitter::List)
415
+ end
416
+
417
+ def cursor_from_response_with_list(request_method, path, args)
418
+ arguments = Twitter::Arguments.new(args)
419
+ merge_list!(arguments.options, arguments.pop)
420
+ merge_owner!(arguments.options, arguments.pop)
421
+ perform_with_cursor(request_method, path, arguments.options, :users, Twitter::User)
422
+ end
423
+
424
+ def list_user?(request_method, path, args)
425
+ arguments = Twitter::Arguments.new(args)
426
+ merge_user!(arguments.options, arguments.pop)
427
+ merge_list!(arguments.options, arguments.pop)
428
+ merge_owner!(arguments.options, arguments.pop)
429
+ send(request_method.to_sym, path, arguments.options)
430
+ true
431
+ rescue Twitter::Error::NotFound, Twitter::Error::Forbidden
432
+ false
433
+ end
434
+
435
+ def list_from_response_with_user(request_method, path, args)
436
+ arguments = Twitter::Arguments.new(args)
437
+ merge_user!(arguments.options, arguments.pop)
438
+ merge_list!(arguments.options, arguments.pop)
439
+ merge_owner!(arguments.options, arguments.pop)
440
+ perform_with_object(request_method, path, arguments.options, Twitter::List)
441
+ end
442
+
443
+ def list_from_response_with_users(request_method, path, args)
444
+ arguments = args.dup
445
+ options = arguments.last.is_a?(::Hash) ? arguments.pop : {}
446
+ members = arguments.pop
447
+ merge_list!(options, arguments.pop)
448
+ merge_owner!(options, arguments.pop)
449
+ parallel_map(members.flatten.each_slice(MAX_USERS_PER_REQUEST)) do |users|
450
+ perform_with_object(request_method, path, merge_users(options, users), Twitter::List)
451
+ end.last
452
+ end
453
+
454
+ # Take a list and merge it into the hash with the correct key
455
+ #
456
+ # @param hash [Hash]
457
+ # @param list [Integer, String, URI, Twitter::List] A Twitter list ID, slug, URI, or object.
458
+ # @return [Hash]
459
+ def merge_list!(hash, list) # rubocop:disable MethodLength
460
+ case list
461
+ when Integer
462
+ hash[:list_id] = list
463
+ when String
464
+ if list[URI_SUBSTRING]
465
+ list = list.split('/')
466
+ hash[:slug] = list.pop
467
+ hash[:owner_screen_name] = list.pop
468
+ else
469
+ hash[:slug] = list
470
+ end
471
+ when URI
472
+ list = list.path.split('/')
473
+ hash[:slug] = list.pop
474
+ hash[:owner_screen_name] = list.pop
475
+ when Twitter::List
476
+ hash[:list_id] = list.id
477
+ merge_owner!(hash, list.user)
478
+ end
479
+ hash
480
+ end
481
+
482
+ # Take an owner and merge it into the hash with the correct key
483
+ #
484
+ # @param hash [Hash]
485
+ # @param user[Integer, String, Twitter::User] A Twitter user ID, screen_name, or object.
486
+ # @return [Hash]
487
+ def merge_owner!(hash, user)
488
+ unless hash[:owner_id] || hash[:owner_screen_name]
489
+ user ||= screen_name
490
+ merge_user!(hash, user, 'owner')
491
+ hash[:owner_id] = hash.delete(:owner_user_id) unless hash[:owner_user_id].nil?
492
+ end
493
+ hash
494
+ end
495
+ end
496
+ end
497
+ end