twitter 4.8.1 → 5.0.0.rc.1
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.
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +30 -0
- data/LICENSE.md +1 -1
- data/README.md +386 -266
- data/lib/twitter.rb +4 -39
- data/lib/twitter/arguments.rb +11 -0
- data/lib/twitter/base.rb +89 -68
- data/lib/twitter/client.rb +69 -110
- data/lib/twitter/configuration.rb +7 -3
- data/lib/twitter/creatable.rb +2 -4
- data/lib/twitter/cursor.rb +50 -42
- data/lib/twitter/direct_message.rb +2 -11
- data/lib/twitter/entity/uri.rb +13 -0
- data/lib/twitter/enumerable.rb +15 -0
- data/lib/twitter/error.rb +55 -7
- data/lib/twitter/error/already_favorited.rb +1 -1
- data/lib/twitter/error/already_posted.rb +10 -0
- data/lib/twitter/error/already_retweeted.rb +1 -1
- data/lib/twitter/error/bad_gateway.rb +2 -3
- data/lib/twitter/error/bad_request.rb +2 -2
- data/lib/twitter/error/forbidden.rb +2 -2
- data/lib/twitter/error/gateway_timeout.rb +2 -3
- data/lib/twitter/error/internal_server_error.rb +2 -3
- data/lib/twitter/error/not_acceptable.rb +2 -2
- data/lib/twitter/error/not_found.rb +2 -2
- data/lib/twitter/error/service_unavailable.rb +2 -3
- data/lib/twitter/error/too_many_requests.rb +2 -2
- data/lib/twitter/error/unauthorized.rb +2 -2
- data/lib/twitter/error/unprocessable_entity.rb +2 -2
- data/lib/twitter/factory.rb +2 -8
- data/lib/twitter/geo_factory.rb +2 -2
- data/lib/twitter/geo_results.rb +36 -0
- data/lib/twitter/identity.rb +0 -22
- data/lib/twitter/list.rb +18 -4
- data/lib/twitter/media/photo.rb +3 -3
- data/lib/twitter/media_factory.rb +2 -2
- data/lib/twitter/null_object.rb +24 -0
- data/lib/twitter/oembed.rb +3 -2
- data/lib/twitter/place.rb +15 -9
- data/lib/twitter/profile_banner.rb +5 -3
- data/lib/twitter/rate_limit.rb +1 -17
- data/lib/twitter/relationship.rb +2 -10
- data/lib/twitter/rest/api/direct_messages.rb +135 -0
- data/lib/twitter/rest/api/favorites.rb +120 -0
- data/lib/twitter/rest/api/friends_and_followers.rb +290 -0
- data/lib/twitter/rest/api/help.rb +58 -0
- data/lib/twitter/rest/api/lists.rb +491 -0
- data/lib/twitter/rest/api/oauth.rb +45 -0
- data/lib/twitter/rest/api/places_and_geo.rb +104 -0
- data/lib/twitter/rest/api/saved_searches.rb +91 -0
- data/lib/twitter/rest/api/search.rb +37 -0
- data/lib/twitter/rest/api/spam_reporting.rb +29 -0
- data/lib/twitter/rest/api/suggested_users.rb +51 -0
- data/lib/twitter/rest/api/timelines.rb +202 -0
- data/lib/twitter/rest/api/trends.rb +58 -0
- data/lib/twitter/rest/api/tweets.rb +293 -0
- data/lib/twitter/rest/api/undocumented.rb +52 -0
- data/lib/twitter/rest/api/users.rb +383 -0
- data/lib/twitter/rest/api/utils.rb +219 -0
- data/lib/twitter/rest/client.rb +193 -0
- data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
- data/lib/twitter/rest/response/parse_json.rb +27 -0
- data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
- data/lib/twitter/search_results.rb +33 -21
- data/lib/twitter/settings.rb +1 -6
- data/lib/twitter/size.rb +1 -1
- data/lib/twitter/streaming/client.rb +77 -0
- data/lib/twitter/streaming/connection.rb +22 -0
- data/lib/twitter/streaming/response.rb +30 -0
- data/lib/twitter/suggestion.rb +4 -2
- data/lib/twitter/token.rb +8 -0
- data/lib/twitter/trend.rb +2 -1
- data/lib/twitter/trend_results.rb +59 -0
- data/lib/twitter/tweet.rb +41 -85
- data/lib/twitter/user.rb +51 -41
- data/lib/twitter/version.rb +4 -4
- data/spec/fixtures/already_posted.json +1 -0
- data/spec/fixtures/ids_list.json +1 -1
- data/spec/fixtures/ids_list2.json +1 -1
- data/spec/fixtures/search.json +1 -1
- data/spec/fixtures/search_malformed.json +1 -1
- data/spec/fixtures/track_streaming.json +3 -0
- data/spec/helper.rb +8 -13
- data/spec/twitter/base_spec.rb +25 -99
- data/spec/twitter/configuration_spec.rb +1 -1
- data/spec/twitter/cursor_spec.rb +13 -31
- data/spec/twitter/direct_message_spec.rb +41 -8
- data/spec/twitter/entity/uri_spec.rb +74 -0
- data/spec/twitter/error_spec.rb +59 -11
- data/spec/twitter/geo/point_spec.rb +1 -1
- data/spec/twitter/geo_factory_spec.rb +3 -3
- data/spec/twitter/geo_results_spec.rb +35 -0
- data/spec/twitter/identifiable_spec.rb +0 -21
- data/spec/twitter/list_spec.rb +51 -8
- data/spec/twitter/media/photo_spec.rb +118 -3
- data/spec/twitter/media_factory_spec.rb +2 -2
- data/spec/twitter/null_object_spec.rb +26 -0
- data/spec/twitter/oembed_spec.rb +69 -45
- data/spec/twitter/place_spec.rb +68 -12
- data/spec/twitter/profile_banner_spec.rb +1 -1
- data/spec/twitter/rate_limit_spec.rb +12 -12
- data/spec/twitter/relationship_spec.rb +31 -9
- data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +22 -9
- data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
- data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +104 -65
- data/spec/twitter/{api → rest/api}/geo_spec.rb +10 -10
- data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
- data/spec/twitter/{api → rest/api}/lists_spec.rb +77 -56
- data/spec/twitter/{api → rest/api}/oauth_spec.rb +6 -6
- data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +7 -7
- data/spec/twitter/{api → rest/api}/search_spec.rb +8 -9
- data/spec/twitter/{api → rest/api}/spam_reporting_spec.rb +3 -3
- data/spec/twitter/{api → rest/api}/suggested_users_spec.rb +5 -5
- data/spec/twitter/{api → rest/api}/timelines_spec.rb +9 -9
- data/spec/twitter/{api → rest/api}/trends_spec.rb +6 -6
- data/spec/twitter/rest/api/tweets_spec.rb +503 -0
- data/spec/twitter/{api → rest/api}/undocumented_spec.rb +19 -45
- data/spec/twitter/{api → rest/api}/users_spec.rb +60 -35
- data/spec/twitter/rest/client_spec.rb +193 -0
- data/spec/twitter/saved_search_spec.rb +11 -0
- data/spec/twitter/search_results_spec.rb +29 -42
- data/spec/twitter/settings_spec.rb +17 -6
- data/spec/twitter/streaming/client_spec.rb +75 -0
- data/spec/twitter/token_spec.rb +16 -0
- data/spec/twitter/trend_results_spec.rb +89 -0
- data/spec/twitter/trend_spec.rb +23 -0
- data/spec/twitter/tweet_spec.rb +122 -115
- data/spec/twitter/user_spec.rb +136 -77
- data/spec/twitter_spec.rb +0 -119
- data/twitter.gemspec +8 -5
- metadata +148 -141
- metadata.gz.sig +0 -0
- data/lib/twitter/action/favorite.rb +0 -19
- data/lib/twitter/action/follow.rb +0 -30
- data/lib/twitter/action/list_member_added.rb +0 -39
- data/lib/twitter/action/mention.rb +0 -46
- data/lib/twitter/action/reply.rb +0 -27
- data/lib/twitter/action/retweet.rb +0 -27
- data/lib/twitter/action/tweet.rb +0 -20
- data/lib/twitter/action_factory.rb +0 -22
- data/lib/twitter/api/arguments.rb +0 -13
- data/lib/twitter/api/direct_messages.rb +0 -148
- data/lib/twitter/api/favorites.rb +0 -126
- data/lib/twitter/api/friends_and_followers.rb +0 -334
- data/lib/twitter/api/help.rb +0 -64
- data/lib/twitter/api/lists.rb +0 -618
- data/lib/twitter/api/oauth.rb +0 -44
- data/lib/twitter/api/places_and_geo.rb +0 -121
- data/lib/twitter/api/saved_searches.rb +0 -99
- data/lib/twitter/api/search.rb +0 -37
- data/lib/twitter/api/spam_reporting.rb +0 -30
- data/lib/twitter/api/suggested_users.rb +0 -55
- data/lib/twitter/api/timelines.rb +0 -214
- data/lib/twitter/api/trends.rb +0 -63
- data/lib/twitter/api/tweets.rb +0 -304
- data/lib/twitter/api/undocumented.rb +0 -97
- data/lib/twitter/api/users.rb +0 -439
- data/lib/twitter/api/utils.rb +0 -187
- data/lib/twitter/configurable.rb +0 -96
- data/lib/twitter/default.rb +0 -102
- data/lib/twitter/entity/url.rb +0 -9
- data/lib/twitter/error/client_error.rb +0 -35
- data/lib/twitter/error/decode_error.rb +0 -9
- data/lib/twitter/error/identity_map_key_error.rb +0 -9
- data/lib/twitter/error/server_error.rb +0 -28
- data/lib/twitter/exceptable.rb +0 -36
- data/lib/twitter/identity_map.rb +0 -22
- data/lib/twitter/request/multipart_with_file.rb +0 -34
- data/lib/twitter/response/parse_json.rb +0 -25
- data/spec/fixtures/about_me.json +0 -1
- data/spec/fixtures/activity_summary.json +0 -1
- data/spec/fixtures/bad_gateway.json +0 -1
- data/spec/fixtures/bad_request.json +0 -1
- data/spec/fixtures/by_friends.json +0 -1
- data/spec/fixtures/end_session.json +0 -1
- data/spec/fixtures/forbidden.json +0 -1
- data/spec/fixtures/internal_server_error.json +0 -1
- data/spec/fixtures/not_acceptable.json +0 -1
- data/spec/fixtures/phoenix_search.phoenix +0 -1
- data/spec/fixtures/resolve.json +0 -1
- data/spec/fixtures/service_unavailable.json +0 -1
- data/spec/fixtures/totals.json +0 -1
- data/spec/fixtures/trends.json +0 -1
- data/spec/fixtures/unauthorized.json +0 -1
- data/spec/fixtures/video_facets.json +0 -1
- data/spec/twitter/action/favorite_spec.rb +0 -29
- data/spec/twitter/action/follow_spec.rb +0 -29
- data/spec/twitter/action/list_member_added_spec.rb +0 -41
- data/spec/twitter/action/mention_spec.rb +0 -52
- data/spec/twitter/action/reply_spec.rb +0 -41
- data/spec/twitter/action/retweet_spec.rb +0 -41
- data/spec/twitter/action_factory_spec.rb +0 -35
- data/spec/twitter/action_spec.rb +0 -16
- data/spec/twitter/api/tweets_spec.rb +0 -285
- data/spec/twitter/client_spec.rb +0 -223
- data/spec/twitter/error/client_error_spec.rb +0 -23
- data/spec/twitter/error/server_error_spec.rb +0 -20
@@ -0,0 +1,491 @@
|
|
1
|
+
require 'twitter/arguments'
|
2
|
+
require 'twitter/core_ext/enumerable'
|
3
|
+
require 'twitter/cursor'
|
4
|
+
require 'twitter/error/forbidden'
|
5
|
+
require 'twitter/error/not_found'
|
6
|
+
require 'twitter/list'
|
7
|
+
require 'twitter/rest/api/utils'
|
8
|
+
require 'twitter/tweet'
|
9
|
+
require 'twitter/user'
|
10
|
+
|
11
|
+
module Twitter
|
12
|
+
module REST
|
13
|
+
module API
|
14
|
+
module Lists
|
15
|
+
include Twitter::REST::API::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 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
|
+
objects_from_response(Twitter::Tweet, :get, "/1.1/lists/statuses.json", arguments.options)
|
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 list_remove_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 list_remove_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 list_remove_member(*args)
|
82
|
+
list_from_response_with_user(:post, "/1.1/lists/members/destroy.json", args)
|
83
|
+
end
|
84
|
+
|
85
|
+
# List the lists the specified user has been added to
|
86
|
+
#
|
87
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/lists/memberships
|
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
|
+
# @overload memberships(options={})
|
93
|
+
# @param options [Hash] A customizable set of options.
|
94
|
+
# @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.
|
95
|
+
# @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.
|
96
|
+
# @overload memberships(user, options={})
|
97
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
98
|
+
# @param options [Hash] A customizable set of options.
|
99
|
+
# @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.
|
100
|
+
# @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.
|
101
|
+
def memberships(*args)
|
102
|
+
cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/memberships.json", args)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Returns the subscribers of the specified list
|
106
|
+
#
|
107
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/lists/subscribers
|
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] The subscribers of the specified list.
|
112
|
+
# @overload list_subscribers(list, options={})
|
113
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
114
|
+
# @param options [Hash] A customizable set of options.
|
115
|
+
# @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.
|
116
|
+
# @overload list_subscribers(user, list, options={})
|
117
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
118
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
119
|
+
# @param options [Hash] A customizable set of options.
|
120
|
+
# @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.
|
121
|
+
def list_subscribers(*args)
|
122
|
+
cursor_from_response_with_list(:get, "/1.1/lists/subscribers.json", args)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Make the authenticated user follow the specified list
|
126
|
+
#
|
127
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/create
|
128
|
+
# @rate_limited No
|
129
|
+
# @authentication Requires user context
|
130
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
131
|
+
# @return [Twitter::List] The specified list.
|
132
|
+
# @overload list_subscribe(list, options={})
|
133
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
134
|
+
# @param options [Hash] A customizable set of options.
|
135
|
+
# @overload list_subscribe(user, list, options={})
|
136
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
137
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
138
|
+
# @param options [Hash] A customizable set of options.
|
139
|
+
def list_subscribe(*args)
|
140
|
+
list_from_response(:post, "/1.1/lists/subscribers/create.json", args)
|
141
|
+
end
|
142
|
+
|
143
|
+
# Check if a user is a subscriber of the specified list
|
144
|
+
#
|
145
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/lists/subscribers/show
|
146
|
+
# @rate_limited Yes
|
147
|
+
# @authentication Requires user context
|
148
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
149
|
+
# @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
|
150
|
+
# @overload list_subscriber?(list, user_to_check, options={})
|
151
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
152
|
+
# @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
153
|
+
# @param options [Hash] A customizable set of options.
|
154
|
+
# @overload list_subscriber?(user, list, user_to_check, options={})
|
155
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
156
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
157
|
+
# @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
158
|
+
# @param options [Hash] A customizable set of options.
|
159
|
+
# @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
|
160
|
+
def list_subscriber?(*args)
|
161
|
+
list_user?(:get, "/1.1/lists/subscribers/show.json", args)
|
162
|
+
end
|
163
|
+
|
164
|
+
# Unsubscribes the authenticated user form the specified list
|
165
|
+
#
|
166
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/destroy
|
167
|
+
# @rate_limited No
|
168
|
+
# @authentication Requires user context
|
169
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
170
|
+
# @return [Twitter::List] The specified list.
|
171
|
+
# @overload list_unsubscribe(list, options={})
|
172
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
173
|
+
# @param options [Hash] A customizable set of options.
|
174
|
+
# @overload list_unsubscribe(user, list, options={})
|
175
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
176
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
177
|
+
# @param options [Hash] A customizable set of options.
|
178
|
+
def list_unsubscribe(*args)
|
179
|
+
list_from_response(:post, "/1.1/lists/subscribers/destroy.json", args)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Adds specified members to a list
|
183
|
+
#
|
184
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/lists/members/create_all
|
185
|
+
# @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.
|
186
|
+
# @rate_limited No
|
187
|
+
# @authentication Requires user context
|
188
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
189
|
+
# @return [Twitter::List] The list.
|
190
|
+
# @overload list_add_members(list, users, options={})
|
191
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
192
|
+
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
|
193
|
+
# @param options [Hash] A customizable set of options.
|
194
|
+
# @overload list_add_members(user, list, users, options={})
|
195
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
196
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
197
|
+
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
|
198
|
+
# @param options [Hash] A customizable set of options.
|
199
|
+
def list_add_members(*args)
|
200
|
+
list_from_response_with_users(:post, "/1.1/lists/members/create_all.json", args)
|
201
|
+
end
|
202
|
+
|
203
|
+
# Check if a user is a member of the specified list
|
204
|
+
#
|
205
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/lists/members/show
|
206
|
+
# @authentication Requires user context
|
207
|
+
# @rate_limited Yes
|
208
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
209
|
+
# @return [Boolean] true if user is a member of the specified list, otherwise false.
|
210
|
+
# @overload list_member?(list, user_to_check, options={})
|
211
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
212
|
+
# @param user_to_check [Integer, String] The user ID or screen name of the list member.
|
213
|
+
# @param options [Hash] A customizable set of options.
|
214
|
+
# @overload list_member?(user, list, user_to_check, options={})
|
215
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
216
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
217
|
+
# @param user_to_check [Integer, String] The user ID or screen name of the list member.
|
218
|
+
# @param options [Hash] A customizable set of options.
|
219
|
+
def list_member?(*args)
|
220
|
+
list_user?(:get, "/1.1/lists/members/show.json", args)
|
221
|
+
end
|
222
|
+
|
223
|
+
# Returns the members of the specified list
|
224
|
+
#
|
225
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/lists/members
|
226
|
+
# @rate_limited Yes
|
227
|
+
# @authentication Requires user context
|
228
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
229
|
+
# @return [Twitter::Cursor]
|
230
|
+
# @overload list_members(list, options={})
|
231
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
232
|
+
# @param options [Hash] A customizable set of options.
|
233
|
+
# @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.
|
234
|
+
# @overload list_members(user, list, options={})
|
235
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
236
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
237
|
+
# @param options [Hash] A customizable set of options.
|
238
|
+
# @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.
|
239
|
+
def list_members(*args)
|
240
|
+
cursor_from_response_with_list(:get, "/1.1/lists/members.json", args)
|
241
|
+
end
|
242
|
+
|
243
|
+
# Add a member to a list
|
244
|
+
#
|
245
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/lists/members/create
|
246
|
+
# @note Lists are limited to having 500 members.
|
247
|
+
# @rate_limited No
|
248
|
+
# @authentication Requires user context
|
249
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
250
|
+
# @return [Twitter::List] The list.
|
251
|
+
# @overload list_add_member(list, user_to_add, options={})
|
252
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
253
|
+
# @param user_to_add [Integer, String] The user id or screen name to add to the list.
|
254
|
+
# @param options [Hash] A customizable set of options.
|
255
|
+
# @overload list_add_member(user, list, user_to_add, options={})
|
256
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
257
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
258
|
+
# @param user_to_add [Integer, String] The user id or screen name to add to the list.
|
259
|
+
# @param options [Hash] A customizable set of options.
|
260
|
+
def list_add_member(*args)
|
261
|
+
list_from_response_with_user(:post, "/1.1/lists/members/create.json", args)
|
262
|
+
end
|
263
|
+
|
264
|
+
# Deletes the specified list
|
265
|
+
#
|
266
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/lists/destroy
|
267
|
+
# @note Must be owned by the authenticated user.
|
268
|
+
# @rate_limited No
|
269
|
+
# @authentication Requires user context
|
270
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
271
|
+
# @return [Twitter::List] The deleted list.
|
272
|
+
# @overload list_destroy(list, options={})
|
273
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
274
|
+
# @param options [Hash] A customizable set of options.
|
275
|
+
# @overload list_destroy(user, list, options={})
|
276
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
277
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
278
|
+
# @param options [Hash] A customizable set of options.
|
279
|
+
def list_destroy(*args)
|
280
|
+
list_from_response(:post, "/1.1/lists/destroy.json", args)
|
281
|
+
end
|
282
|
+
|
283
|
+
# Updates the specified list
|
284
|
+
#
|
285
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/lists/update
|
286
|
+
# @rate_limited No
|
287
|
+
# @authentication Requires user context
|
288
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
289
|
+
# @return [Twitter::List] The created list.
|
290
|
+
# @overload list_update(list, options={})
|
291
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
292
|
+
# @param options [Hash] A customizable set of options.
|
293
|
+
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
|
294
|
+
# @option options [String] :description The description to give the list.
|
295
|
+
# @overload list_update(user, list, options={})
|
296
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
297
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
298
|
+
# @param options [Hash] A customizable set of options.
|
299
|
+
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
|
300
|
+
# @option options [String] :description The description to give the list.
|
301
|
+
def list_update(*args)
|
302
|
+
list_from_response(:post, "/1.1/lists/update.json", args)
|
303
|
+
end
|
304
|
+
|
305
|
+
# Creates a new list for the authenticated user
|
306
|
+
#
|
307
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/lists/create
|
308
|
+
# @note Accounts are limited to 20 lists.
|
309
|
+
# @rate_limited No
|
310
|
+
# @authentication Requires user context
|
311
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
312
|
+
# @return [Twitter::List] The created list.
|
313
|
+
# @param name [String] The name for the list.
|
314
|
+
# @param options [Hash] A customizable set of options.
|
315
|
+
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
|
316
|
+
# @option options [String] :description The description to give the list.
|
317
|
+
def list_create(name, options={})
|
318
|
+
object_from_response(Twitter::List, :post, "/1.1/lists/create.json", options.merge(:name => name))
|
319
|
+
end
|
320
|
+
|
321
|
+
# Show the specified list
|
322
|
+
#
|
323
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/lists/show
|
324
|
+
# @note Private lists will only be shown if the authenticated user owns the specified list.
|
325
|
+
# @rate_limited Yes
|
326
|
+
# @authentication Requires user context
|
327
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
328
|
+
# @return [Twitter::List] The specified list.
|
329
|
+
# @overload list(list, options={})
|
330
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
331
|
+
# @param options [Hash] A customizable set of options.
|
332
|
+
# @overload list(user, list, options={})
|
333
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
334
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
335
|
+
# @param options [Hash] A customizable set of options.
|
336
|
+
def list(*args)
|
337
|
+
list_from_response(:get, "/1.1/lists/show.json", args)
|
338
|
+
end
|
339
|
+
|
340
|
+
# List the lists the specified user follows
|
341
|
+
#
|
342
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/lists/subscriptions
|
343
|
+
# @rate_limited Yes
|
344
|
+
# @authentication Requires user context
|
345
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
346
|
+
# @return [Twitter::Cursor]
|
347
|
+
# @overload subscriptions(options={})
|
348
|
+
# @param options [Hash] A customizable set of options.
|
349
|
+
# @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.
|
350
|
+
# @overload subscriptions(user, options={})
|
351
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
352
|
+
# @param options [Hash] A customizable set of options.
|
353
|
+
# @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.
|
354
|
+
def subscriptions(*args)
|
355
|
+
cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/subscriptions.json", args)
|
356
|
+
end
|
357
|
+
|
358
|
+
# Removes specified members from the list
|
359
|
+
#
|
360
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy_all
|
361
|
+
# @rate_limited No
|
362
|
+
# @authentication Requires user context
|
363
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
364
|
+
# @return [Twitter::List] The list.
|
365
|
+
# @overload list_remove_members(list, users, options={})
|
366
|
+
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
367
|
+
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
|
368
|
+
# @param options [Hash] A customizable set of options.
|
369
|
+
# @overload list_remove_members(user, list, users, options={})
|
370
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
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
|
+
def list_remove_members(*args)
|
375
|
+
list_from_response_with_users(:post, "/1.1/lists/members/destroy_all.json", args)
|
376
|
+
end
|
377
|
+
|
378
|
+
# Returns the lists owned by the specified Twitter user
|
379
|
+
#
|
380
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/lists/ownerships
|
381
|
+
# @rate_limited Yes
|
382
|
+
# @authentication Requires user context
|
383
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
384
|
+
# @return [Array<Twitter::List>]
|
385
|
+
# @overload lists_owned(options={})
|
386
|
+
# @param options [Hash] A customizable set of options.
|
387
|
+
# @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.
|
388
|
+
# @overload lists_owned(user, options={})
|
389
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
390
|
+
# @param options [Hash] A customizable set of options.
|
391
|
+
# @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.
|
392
|
+
def lists_owned(*args)
|
393
|
+
cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/ownerships.json", args)
|
394
|
+
end
|
395
|
+
alias lists_ownerships lists_owned
|
396
|
+
|
397
|
+
private
|
398
|
+
|
399
|
+
# @param request_method [Symbol]
|
400
|
+
# @param path [String]
|
401
|
+
# @param args [Array]
|
402
|
+
# @return [Array<Twitter::User>]
|
403
|
+
def list_from_response(request_method, path, args)
|
404
|
+
arguments = Twitter::Arguments.new(args)
|
405
|
+
merge_list!(arguments.options, arguments.pop)
|
406
|
+
merge_owner!(arguments.options, arguments.pop)
|
407
|
+
object_from_response(Twitter::List, request_method, path, arguments.options)
|
408
|
+
end
|
409
|
+
|
410
|
+
def cursor_from_response_with_list(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
|
+
cursor_from_response(:users, Twitter::User, request_method, path, arguments.options)
|
415
|
+
end
|
416
|
+
|
417
|
+
def list_user?(request_method, path, args)
|
418
|
+
arguments = Twitter::Arguments.new(args)
|
419
|
+
merge_user!(arguments.options, arguments.pop)
|
420
|
+
merge_list!(arguments.options, arguments.pop)
|
421
|
+
merge_owner!(arguments.options, arguments.pop)
|
422
|
+
send(request_method.to_sym, path, arguments.options)
|
423
|
+
true
|
424
|
+
rescue Twitter::Error::NotFound, Twitter::Error::Forbidden
|
425
|
+
false
|
426
|
+
end
|
427
|
+
|
428
|
+
def list_from_response_with_user(request_method, path, args)
|
429
|
+
arguments = Twitter::Arguments.new(args)
|
430
|
+
merge_user!(arguments.options, arguments.pop)
|
431
|
+
merge_list!(arguments.options, arguments.pop)
|
432
|
+
merge_owner!(arguments.options, arguments.pop)
|
433
|
+
object_from_response(Twitter::List, request_method, path, arguments.options)
|
434
|
+
end
|
435
|
+
|
436
|
+
def list_from_response_with_users(request_method, path, args)
|
437
|
+
arguments = Twitter::Arguments.new(args)
|
438
|
+
members = arguments.pop
|
439
|
+
merge_list!(arguments.options, arguments.pop)
|
440
|
+
merge_owner!(arguments.options, arguments.pop)
|
441
|
+
members.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
|
442
|
+
object_from_response(Twitter::List, request_method, path, merge_users(arguments.options, users))
|
443
|
+
end.last
|
444
|
+
end
|
445
|
+
|
446
|
+
# Take a list and merge it into the hash with the correct key
|
447
|
+
#
|
448
|
+
# @param hash [Hash]
|
449
|
+
# @param list [Integer, String, URI, Twitter::List] A Twitter list ID, slug, URI, or object.
|
450
|
+
# @return [Hash]
|
451
|
+
def merge_list!(hash, list)
|
452
|
+
case list
|
453
|
+
when Integer
|
454
|
+
hash[:list_id] = list
|
455
|
+
when String
|
456
|
+
if list[URI_SUBSTRING]
|
457
|
+
list = list.split("/")
|
458
|
+
hash[:slug] = list.pop
|
459
|
+
hash[:owner_screen_name] = list.pop
|
460
|
+
else
|
461
|
+
hash[:slug] = list
|
462
|
+
end
|
463
|
+
when URI
|
464
|
+
list = list.path.split("/")
|
465
|
+
hash[:slug] = list.pop
|
466
|
+
hash[:owner_screen_name] = list.pop
|
467
|
+
when Twitter::List
|
468
|
+
hash[:list_id] = list.id
|
469
|
+
merge_owner!(hash, list.user)
|
470
|
+
end
|
471
|
+
hash
|
472
|
+
end
|
473
|
+
|
474
|
+
# Take an owner and merge it into the hash with the correct key
|
475
|
+
#
|
476
|
+
# @param hash [Hash]
|
477
|
+
# @param user[Integer, String, Twitter::User] A Twitter user ID, screen_name, or object.
|
478
|
+
# @return [Hash]
|
479
|
+
def merge_owner!(hash, user)
|
480
|
+
unless hash[:owner_id] || hash[:owner_screen_name]
|
481
|
+
user ||= screen_name
|
482
|
+
merge_user!(hash, user, "owner")
|
483
|
+
hash[:owner_id] = hash.delete(:owner_user_id) unless hash[:owner_user_id].nil?
|
484
|
+
end
|
485
|
+
hash
|
486
|
+
end
|
487
|
+
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
491
|
+
end
|