twitter 5.6.0 → 5.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +8 -0
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/lib/twitter/base.rb +0 -8
- data/lib/twitter/client.rb +2 -1
- data/lib/twitter/cursor.rb +2 -15
- data/lib/twitter/error.rb +90 -18
- data/lib/twitter/geo_results.rb +0 -10
- data/lib/twitter/request.rb +4 -4
- data/lib/twitter/rest/api.rb +43 -0
- data/lib/twitter/rest/client.rb +10 -44
- data/lib/twitter/rest/direct_messages.rb +138 -0
- data/lib/twitter/rest/favorites.rb +108 -0
- data/lib/twitter/rest/friends_and_followers.rb +281 -0
- data/lib/twitter/rest/help.rb +56 -0
- data/lib/twitter/rest/lists.rb +497 -0
- data/lib/twitter/rest/oauth.rb +65 -0
- data/lib/twitter/rest/places_and_geo.rb +84 -0
- data/lib/twitter/rest/request/multipart_with_file.rb +5 -5
- data/lib/twitter/rest/response/parse_json.rb +2 -4
- data/lib/twitter/rest/response/raise_error.rb +24 -15
- data/lib/twitter/rest/saved_searches.rb +93 -0
- data/lib/twitter/rest/search.rb +37 -0
- data/lib/twitter/rest/spam_reporting.rb +27 -0
- data/lib/twitter/rest/suggested_users.rb +49 -0
- data/lib/twitter/rest/timelines.rb +200 -0
- data/lib/twitter/rest/trends.rb +57 -0
- data/lib/twitter/rest/tweets.rb +309 -0
- data/lib/twitter/rest/undocumented.rb +49 -0
- data/lib/twitter/rest/users.rb +383 -0
- data/lib/twitter/rest/utils.rb +205 -0
- data/lib/twitter/search_results.rb +2 -13
- data/lib/twitter/trend_results.rb +0 -10
- data/lib/twitter/version.rb +1 -1
- data/spec/helper.rb +1 -1
- data/spec/twitter/error_spec.rb +26 -42
- data/spec/twitter/rest/{api/direct_messages_spec.rb → direct_messages_spec.rb} +1 -1
- data/spec/twitter/rest/{api/favorites_spec.rb → favorites_spec.rb} +1 -1
- data/spec/twitter/rest/{api/friends_and_followers_spec.rb → friends_and_followers_spec.rb} +1 -1
- data/spec/twitter/rest/{api/geo_spec.rb → geo_spec.rb} +1 -1
- data/spec/twitter/rest/{api/help_spec.rb → help_spec.rb} +1 -1
- data/spec/twitter/rest/{api/lists_spec.rb → lists_spec.rb} +1 -1
- data/spec/twitter/rest/{api/oauth_spec.rb → oauth_spec.rb} +4 -8
- data/spec/twitter/rest/{api/saved_searches_spec.rb → saved_searches_spec.rb} +1 -1
- data/spec/twitter/rest/{api/search_spec.rb → search_spec.rb} +1 -1
- data/spec/twitter/rest/{api/spam_reporting_spec.rb → spam_reporting_spec.rb} +1 -1
- data/spec/twitter/rest/{api/suggested_users_spec.rb → suggested_users_spec.rb} +1 -1
- data/spec/twitter/rest/{api/timelines_spec.rb → timelines_spec.rb} +1 -1
- data/spec/twitter/rest/{api/trends_spec.rb → trends_spec.rb} +1 -1
- data/spec/twitter/rest/{api/tweets_spec.rb → tweets_spec.rb} +74 -5
- data/spec/twitter/rest/{api/undocumented_spec.rb → undocumented_spec.rb} +1 -1
- data/spec/twitter/rest/{api/users_spec.rb → users_spec.rb} +5 -5
- data/spec/twitter/tweet_spec.rb +1 -1
- data/twitter.gemspec +0 -1
- metadata +247 -237
- metadata.gz.sig +0 -0
- checksums.yaml +0 -7
- checksums.yaml.gz.sig +0 -0
- data/lib/twitter/error/already_favorited.rb +0 -10
- data/lib/twitter/error/already_posted.rb +0 -10
- data/lib/twitter/error/already_retweeted.rb +0 -10
- data/lib/twitter/error/bad_gateway.rb +0 -10
- data/lib/twitter/error/bad_request.rb +0 -10
- data/lib/twitter/error/configuration_error.rb +0 -8
- data/lib/twitter/error/forbidden.rb +0 -10
- data/lib/twitter/error/gateway_timeout.rb +0 -10
- data/lib/twitter/error/internal_server_error.rb +0 -10
- data/lib/twitter/error/not_acceptable.rb +0 -10
- data/lib/twitter/error/not_found.rb +0 -10
- data/lib/twitter/error/request_timeout.rb +0 -10
- data/lib/twitter/error/service_unavailable.rb +0 -10
- data/lib/twitter/error/too_many_requests.rb +0 -12
- data/lib/twitter/error/unauthorized.rb +0 -10
- data/lib/twitter/error/unprocessable_entity.rb +0 -10
- data/lib/twitter/rest/api/direct_messages.rb +0 -140
- data/lib/twitter/rest/api/favorites.rb +0 -115
- data/lib/twitter/rest/api/friends_and_followers.rb +0 -284
- data/lib/twitter/rest/api/help.rb +0 -58
- data/lib/twitter/rest/api/lists.rb +0 -500
- data/lib/twitter/rest/api/oauth.rb +0 -67
- data/lib/twitter/rest/api/places_and_geo.rb +0 -86
- data/lib/twitter/rest/api/saved_searches.rb +0 -95
- data/lib/twitter/rest/api/search.rb +0 -39
- data/lib/twitter/rest/api/spam_reporting.rb +0 -29
- data/lib/twitter/rest/api/suggested_users.rb +0 -51
- data/lib/twitter/rest/api/timelines.rb +0 -202
- data/lib/twitter/rest/api/trends.rb +0 -58
- data/lib/twitter/rest/api/tweets.rb +0 -297
- data/lib/twitter/rest/api/undocumented.rb +0 -51
- data/lib/twitter/rest/api/users.rb +0 -383
- data/lib/twitter/rest/api/utils.rb +0 -212
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'twitter/place'
|
2
|
+
require 'twitter/request'
|
3
|
+
require 'twitter/rest/utils'
|
4
|
+
require 'twitter/trend_results'
|
5
|
+
|
6
|
+
module Twitter
|
7
|
+
module REST
|
8
|
+
module Trends
|
9
|
+
include Twitter::REST::Utils
|
10
|
+
|
11
|
+
# Returns the top 10 trending topics for a specific WOEID
|
12
|
+
#
|
13
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/trends/place
|
14
|
+
# @rate_limited Yes
|
15
|
+
# @authentication Requires user context
|
16
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
17
|
+
# @param id [Integer] The {https://developer.yahoo.com/geo/geoplanet Yahoo! Where On Earth ID} of the location to return trending information for. WOEIDs can be retrieved by calling {Twitter::REST::Trends#trends_available}. Global information is available by using 1 as the WOEID.
|
18
|
+
# @param options [Hash] A customizable set of options.
|
19
|
+
# @option options [String] :exclude Setting this equal to 'hashtags' will remove all hashtags from the trends list.
|
20
|
+
# @return [Array<Twitter::Trend>]
|
21
|
+
def trends(id = 1, options = {})
|
22
|
+
options[:id] = id
|
23
|
+
response = get('/1.1/trends/place.json', options).body.first
|
24
|
+
Twitter::TrendResults.new(response)
|
25
|
+
end
|
26
|
+
alias_method :local_trends, :trends
|
27
|
+
alias_method :trends_place, :trends
|
28
|
+
|
29
|
+
# Returns the locations that Twitter has trending topic information for
|
30
|
+
#
|
31
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/trends/available
|
32
|
+
# @rate_limited Yes
|
33
|
+
# @authentication Requires user context
|
34
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
35
|
+
# @param options [Hash] A customizable set of options.
|
36
|
+
# @return [Array<Twitter::Place>]
|
37
|
+
def trends_available(options = {})
|
38
|
+
perform_with_objects(:get, '/1.1/trends/available.json', options, Twitter::Place)
|
39
|
+
end
|
40
|
+
alias_method :trend_locations, :trends_available
|
41
|
+
|
42
|
+
# Returns the locations that Twitter has trending topic information for, closest to a specified location.
|
43
|
+
#
|
44
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/trends/closest
|
45
|
+
# @rate_limited Yes
|
46
|
+
# @authentication Requires user context
|
47
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
48
|
+
# @param options [Hash] A customizable set of options.
|
49
|
+
# @option options [Float] :lat If provided with a :long option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for latitude are -90.0 to +90.0 (North is positive) inclusive.
|
50
|
+
# @option options [Float] :long If provided with a :lat option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for longitude are -180.0 to +180.0 (East is positive) inclusive.
|
51
|
+
# @return [Array<Twitter::Place>]
|
52
|
+
def trends_closest(options = {})
|
53
|
+
perform_with_objects(:get, '/1.1/trends/closest.json', options, Twitter::Place)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,309 @@
|
|
1
|
+
require 'twitter/arguments'
|
2
|
+
require 'twitter/error'
|
3
|
+
require 'twitter/oembed'
|
4
|
+
require 'twitter/request'
|
5
|
+
require 'twitter/rest/utils'
|
6
|
+
require 'twitter/tweet'
|
7
|
+
require 'twitter/utils'
|
8
|
+
|
9
|
+
module Twitter
|
10
|
+
module REST
|
11
|
+
module Tweets
|
12
|
+
include Twitter::REST::Utils
|
13
|
+
include Twitter::Utils
|
14
|
+
|
15
|
+
# Returns up to 100 of the first retweets of a given tweet
|
16
|
+
#
|
17
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id
|
18
|
+
# @rate_limited Yes
|
19
|
+
# @authentication Requires user context
|
20
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
21
|
+
# @return [Array<Twitter::Tweet>]
|
22
|
+
# @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
|
23
|
+
# @param options [Hash] A customizable set of options.
|
24
|
+
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
|
25
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
26
|
+
def retweets(tweet, options = {})
|
27
|
+
perform_with_objects(:get, "/1.1/statuses/retweets/#{extract_id(tweet)}.json", options, Twitter::Tweet)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Show up to 100 users who retweeted the Tweet
|
31
|
+
#
|
32
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id
|
33
|
+
# @rate_limited Yes
|
34
|
+
# @authentication Requires user context
|
35
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
36
|
+
# @return [Array]
|
37
|
+
# @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
|
38
|
+
# @param options [Hash] A customizable set of options.
|
39
|
+
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
|
40
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
41
|
+
# @option options [Boolean] :ids_only ('false') Only return user ids instead of full user objects.
|
42
|
+
def retweeters_of(tweet, options = {})
|
43
|
+
ids_only = !!options.delete(:ids_only)
|
44
|
+
retweeters = retweets(tweet, options).collect(&:user)
|
45
|
+
ids_only ? retweeters.collect(&:id) : retweeters
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns a Tweet
|
49
|
+
#
|
50
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/show/:id
|
51
|
+
# @rate_limited Yes
|
52
|
+
# @authentication Requires user context
|
53
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
54
|
+
# @raise [Twitter::Error::Forbidden] Error raised when supplied status is over 140 characters.
|
55
|
+
# @return [Twitter::Tweet] The requested Tweet.
|
56
|
+
# @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
|
57
|
+
# @param options [Hash] A customizable set of options.
|
58
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
59
|
+
def status(tweet, options = {})
|
60
|
+
perform_with_object(:get, "/1.1/statuses/show/#{extract_id(tweet)}.json", options, Twitter::Tweet)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns Tweets
|
64
|
+
#
|
65
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/show/:id
|
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::Tweet>] The requested Tweets.
|
70
|
+
# @overload statuses(*tweets)
|
71
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
72
|
+
# @overload statuses(*tweets, options)
|
73
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
74
|
+
# @param options [Hash] A customizable set of options.
|
75
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
76
|
+
def statuses(*args)
|
77
|
+
parallel_tweets_from_response(:get, '/1.1/statuses/show', args)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Destroys the specified Tweets
|
81
|
+
#
|
82
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/:id
|
83
|
+
# @note The authenticating user must be the author of the specified Tweets.
|
84
|
+
# @rate_limited No
|
85
|
+
# @authentication Requires user context
|
86
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
87
|
+
# @return [Array<Twitter::Tweet>] The deleted Tweets.
|
88
|
+
# @overload destroy_status(*tweets)
|
89
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
90
|
+
# @overload destroy_status(*tweets, options)
|
91
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
92
|
+
# @param options [Hash] A customizable set of options.
|
93
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
94
|
+
def destroy_status(*args)
|
95
|
+
parallel_tweets_from_response(:post, '/1.1/statuses/destroy', args)
|
96
|
+
end
|
97
|
+
alias_method :destroy_tweet, :destroy_status
|
98
|
+
deprecate_alias :status_destroy, :destroy_status
|
99
|
+
deprecate_alias :tweet_destroy, :destroy_status
|
100
|
+
|
101
|
+
# Updates the authenticating user's status
|
102
|
+
#
|
103
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/statuses/update
|
104
|
+
# @note A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.
|
105
|
+
# @rate_limited No
|
106
|
+
# @authentication Requires user context
|
107
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
108
|
+
# @return [Twitter::Tweet] The created Tweet.
|
109
|
+
# @param status [String] The text of your status update, up to 140 characters.
|
110
|
+
# @param options [Hash] A customizable set of options.
|
111
|
+
# @option options [Twitter::Tweet] :in_reply_to_status An existing status that the update is in reply to.
|
112
|
+
# @option options [Integer] :in_reply_to_status_id The ID of an existing status that the update is in reply to.
|
113
|
+
# @option options [Float] :lat The latitude of the location this tweet refers to. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
|
114
|
+
# @option options [Float] :long The longitude of the location this tweet refers to. The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
|
115
|
+
# @option options [Twitter::Place] :place A place in the world. These can be retrieved from {Twitter::REST::PlacesAndGeo#reverse_geocode}.
|
116
|
+
# @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::REST::PlacesAndGeo#reverse_geocode}.
|
117
|
+
# @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
|
118
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
119
|
+
def update(status, options = {})
|
120
|
+
update!(status, options)
|
121
|
+
rescue Twitter::Error::DuplicateStatus
|
122
|
+
user_timeline(:count => 1).first
|
123
|
+
end
|
124
|
+
|
125
|
+
# Updates the authenticating user's status
|
126
|
+
#
|
127
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/statuses/update
|
128
|
+
# @note A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.
|
129
|
+
# @rate_limited No
|
130
|
+
# @authentication Requires user context
|
131
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
132
|
+
# @raise [Twitter::Error::DuplicateStatus] Error raised when a duplicate status is posted.
|
133
|
+
# @return [Twitter::Tweet] The created Tweet.
|
134
|
+
# @param status [String] The text of your status update, up to 140 characters.
|
135
|
+
# @param options [Hash] A customizable set of options.
|
136
|
+
# @option options [Twitter::Tweet] :in_reply_to_status An existing status that the update is in reply to.
|
137
|
+
# @option options [Integer] :in_reply_to_status_id The ID of an existing status that the update is in reply to.
|
138
|
+
# @option options [Float] :lat The latitude of the location this tweet refers to. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
|
139
|
+
# @option options [Float] :long The longitude of the location this tweet refers to. The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
|
140
|
+
# @option options [Twitter::Place] :place A place in the world. These can be retrieved from {Twitter::REST::PlacesAndGeo#reverse_geocode}.
|
141
|
+
# @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::REST::PlacesAndGeo#reverse_geocode}.
|
142
|
+
# @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
|
143
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
144
|
+
def update!(status, options = {})
|
145
|
+
hash = options.dup
|
146
|
+
hash[:in_reply_to_status_id] = hash.delete(:in_reply_to_status).id unless hash[:in_reply_to_status].nil?
|
147
|
+
hash[:place_id] = hash.delete(:place).woeid unless hash[:place].nil?
|
148
|
+
perform_with_object(:post, '/1.1/statuses/update.json', hash.merge(:status => status), Twitter::Tweet)
|
149
|
+
end
|
150
|
+
|
151
|
+
# Retweets the specified Tweets as the authenticating user
|
152
|
+
#
|
153
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/:id
|
154
|
+
# @rate_limited Yes
|
155
|
+
# @authentication Requires user context
|
156
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
157
|
+
# @return [Array<Twitter::Tweet>] The original tweets with retweet details embedded.
|
158
|
+
# @overload retweet(*tweets)
|
159
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
160
|
+
# @overload retweet(*tweets, options)
|
161
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
162
|
+
# @param options [Hash] A customizable set of options.
|
163
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
164
|
+
def retweet(*args)
|
165
|
+
arguments = Twitter::Arguments.new(args)
|
166
|
+
parallel_map(arguments) do |tweet|
|
167
|
+
begin
|
168
|
+
post_retweet(extract_id(tweet), arguments.options)
|
169
|
+
rescue Twitter::Error::AlreadyRetweeted
|
170
|
+
next
|
171
|
+
end
|
172
|
+
end.compact
|
173
|
+
end
|
174
|
+
|
175
|
+
# Retweets the specified Tweets as the authenticating user and raises an error if one has already been retweeted
|
176
|
+
#
|
177
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/:id
|
178
|
+
# @rate_limited Yes
|
179
|
+
# @authentication Requires user context
|
180
|
+
# @raise [Twitter::Error::AlreadyRetweeted] Error raised when tweet has already been retweeted.
|
181
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
182
|
+
# @return [Array<Twitter::Tweet>] The original tweets with retweet details embedded.
|
183
|
+
# @overload retweet!(*tweets)
|
184
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
185
|
+
# @overload retweet!(*tweets, options)
|
186
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
187
|
+
# @param options [Hash] A customizable set of options.
|
188
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
189
|
+
def retweet!(*args)
|
190
|
+
arguments = Twitter::Arguments.new(args)
|
191
|
+
parallel_map(arguments) do |tweet|
|
192
|
+
post_retweet(extract_id(tweet), arguments.options)
|
193
|
+
end.compact
|
194
|
+
end
|
195
|
+
|
196
|
+
# Updates the authenticating user's status with media
|
197
|
+
#
|
198
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media
|
199
|
+
# @note A status update with text/media identical to the authenticating user's current status will NOT be ignored
|
200
|
+
# @rate_limited No
|
201
|
+
# @authentication Requires user context
|
202
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
203
|
+
# @return [Twitter::Tweet] The created Tweet.
|
204
|
+
# @param status [String] The text of your status update, up to 140 characters.
|
205
|
+
# @param media [File, Hash] A File object with your picture (PNG, JPEG or GIF)
|
206
|
+
# @param options [Hash] A customizable set of options.
|
207
|
+
# @option options [Boolean, String, Integer] :possibly_sensitive Set to true for content which may not be suitable for every audience.
|
208
|
+
# @option options [Twitter::Tweet] :in_reply_to_status An existing status that the update is in reply to.
|
209
|
+
# @option options [Integer] :in_reply_to_status_id The ID of an existing Tweet that the update is in reply to.
|
210
|
+
# @option options [Float] :lat The latitude of the location this tweet refers to. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
|
211
|
+
# @option options [Float] :long The longitude of the location this tweet refers to. The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
|
212
|
+
# @option options [Twitter::Place] :place A place in the world. These can be retrieved from {Twitter::REST::PlacesAndGeo#reverse_geocode}.
|
213
|
+
# @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::REST::PlacesAndGeo#reverse_geocode}.
|
214
|
+
# @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
|
215
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
216
|
+
def update_with_media(status, media, options = {})
|
217
|
+
hash = options.dup
|
218
|
+
hash[:in_reply_to_status_id] = hash.delete(:in_reply_to_status).id unless hash[:in_reply_to_status].nil?
|
219
|
+
hash[:place_id] = hash.delete(:place).woeid unless hash[:place].nil?
|
220
|
+
perform_with_object(:post, '/1.1/statuses/update_with_media.json', hash.merge('media[]' => media, 'status' => status), Twitter::Tweet)
|
221
|
+
end
|
222
|
+
|
223
|
+
# Returns oEmbed for a Tweet
|
224
|
+
#
|
225
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/oembed
|
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::OEmbed] OEmbed for the requested Tweet.
|
230
|
+
# @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
|
231
|
+
# @param options [Hash] A customizable set of options.
|
232
|
+
# @option options [Integer] :maxwidth The maximum width in pixels that the embed should be rendered at. This value is constrained to be between 250 and 550 pixels.
|
233
|
+
# @option options [Boolean, String, Integer] :hide_media Specifies whether the embedded Tweet should automatically expand images which were uploaded via {https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media POST statuses/update_with_media}. When set to either true, t or 1 images will not be expanded. Defaults to false.
|
234
|
+
# @option options [Boolean, String, Integer] :hide_thread Specifies whether the embedded Tweet should automatically show the original message in the case that the embedded Tweet is a reply. When set to either true, t or 1 the original Tweet will not be shown. Defaults to false.
|
235
|
+
# @option options [Boolean, String, Integer] :omit_script Specifies whether the embedded Tweet HTML should include a `<script>` element pointing to widgets.js. In cases where a page already includes widgets.js, setting this value to true will prevent a redundant script element from being included. When set to either true, t or 1 the `<script>` element will not be included in the embed HTML, meaning that pages must include a reference to widgets.js manually. Defaults to false.
|
236
|
+
# @option options [String] :align Specifies whether the embedded Tweet should be left aligned, right aligned, or centered in the page. Valid values are left, right, center, and none. Defaults to none, meaning no alignment styles are specified for the Tweet.
|
237
|
+
# @option options [String] :related A value for the TWT related parameter, as described in {https://dev.twitter.com/docs/intents Web Intents}. This value will be forwarded to all Web Intents calls.
|
238
|
+
# @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
|
239
|
+
def oembed(tweet, options = {})
|
240
|
+
options[:id] = extract_id(tweet)
|
241
|
+
perform_with_object(:get, '/1.1/statuses/oembed.json', options, Twitter::OEmbed)
|
242
|
+
end
|
243
|
+
|
244
|
+
# Returns oEmbeds for Tweets
|
245
|
+
#
|
246
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/oembed
|
247
|
+
# @rate_limited Yes
|
248
|
+
# @authentication Requires user context
|
249
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
250
|
+
# @return [Array<Twitter::OEmbed>] OEmbeds for the requested Tweets.
|
251
|
+
# @overload oembed(*tweets)
|
252
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
253
|
+
# @overload oembed(*tweets, options)
|
254
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
255
|
+
# @param options [Hash] A customizable set of options.
|
256
|
+
# @option options [Integer] :maxwidth The maximum width in pixels that the embed should be rendered at. This value is constrained to be between 250 and 550 pixels.
|
257
|
+
# @option options [Boolean, String, Integer] :hide_media Specifies whether the embedded Tweet should automatically expand images which were uploaded via {https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media POST statuses/update_with_media}. When set to either true, t or 1 images will not be expanded. Defaults to false.
|
258
|
+
# @option options [Boolean, String, Integer] :hide_thread Specifies whether the embedded Tweet should automatically show the original message in the case that the embedded Tweet is a reply. When set to either true, t or 1 the original Tweet will not be shown. Defaults to false.
|
259
|
+
# @option options [Boolean, String, Integer] :omit_script Specifies whether the embedded Tweet HTML should include a `<script>` element pointing to widgets.js. In cases where a page already includes widgets.js, setting this value to true will prevent a redundant script element from being included. When set to either true, t or 1 the `<script>` element will not be included in the embed HTML, meaning that pages must include a reference to widgets.js manually. Defaults to false.
|
260
|
+
# @option options [String] :align Specifies whether the embedded Tweet should be left aligned, right aligned, or centered in the page. Valid values are left, right, center, and none. Defaults to none, meaning no alignment styles are specified for the Tweet.
|
261
|
+
# @option options [String] :related A value for the TWT related parameter, as described in {https://dev.twitter.com/docs/intents Web Intents}. This value will be forwarded to all Web Intents calls.
|
262
|
+
# @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
|
263
|
+
def oembeds(*args)
|
264
|
+
arguments = Twitter::Arguments.new(args)
|
265
|
+
parallel_map(arguments) do |tweet|
|
266
|
+
oembed(extract_id(tweet), arguments.options)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
# Returns a collection of up to 100 user IDs belonging to users who have retweeted the tweet specified by the id parameter.
|
271
|
+
#
|
272
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweeters/ids
|
273
|
+
# @rate_limited Yes
|
274
|
+
# @authentication Required
|
275
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
276
|
+
# @return [Twitter::Cursor]
|
277
|
+
# @overload retweeters_ids(options)
|
278
|
+
# @param options [Hash] A customizable set of options.
|
279
|
+
# @overload retweeters_ids(id, options = {})
|
280
|
+
# @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
|
281
|
+
# @param options [Hash] A customizable set of options.
|
282
|
+
def retweeters_ids(*args)
|
283
|
+
arguments = Twitter::Arguments.new(args)
|
284
|
+
arguments.options[:id] ||= extract_id(arguments.first)
|
285
|
+
perform_with_cursor(:get, '/1.1/statuses/retweeters/ids.json', arguments.options, :ids)
|
286
|
+
end
|
287
|
+
|
288
|
+
private
|
289
|
+
|
290
|
+
# @param request_method [Symbol]
|
291
|
+
# @param path [String]
|
292
|
+
# @param args [Array]
|
293
|
+
# @return [Array<Twitter::Tweet>]
|
294
|
+
def parallel_tweets_from_response(request_method, path, args)
|
295
|
+
arguments = Twitter::Arguments.new(args)
|
296
|
+
parallel_map(arguments) do |tweet|
|
297
|
+
perform_with_object(request_method, path + "/#{extract_id(tweet)}.json", arguments.options, Twitter::Tweet)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def post_retweet(tweet, options)
|
302
|
+
response = post("/1.1/statuses/retweet/#{extract_id(tweet)}.json", options).body
|
303
|
+
retweeted_status = response.delete(:retweeted_status)
|
304
|
+
retweeted_status[:retweeted_status] = response
|
305
|
+
Twitter::Tweet.new(retweeted_status)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'twitter/arguments'
|
2
|
+
require 'twitter/cursor'
|
3
|
+
require 'twitter/rest/utils'
|
4
|
+
require 'twitter/tweet'
|
5
|
+
require 'twitter/user'
|
6
|
+
|
7
|
+
module Twitter
|
8
|
+
module REST
|
9
|
+
module Undocumented
|
10
|
+
include Twitter::REST::Utils
|
11
|
+
|
12
|
+
# @note Undocumented
|
13
|
+
# @rate_limited Yes
|
14
|
+
# @authentication Requires user context
|
15
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
16
|
+
#
|
17
|
+
# @overload following_followers_of(options = {})
|
18
|
+
# Returns users following followers of the specified user
|
19
|
+
#
|
20
|
+
# @param options [Hash] A customizable set of options.
|
21
|
+
# @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.
|
22
|
+
# @return [Twitter::Cursor]
|
23
|
+
#
|
24
|
+
# @overload following_followers_of(user, options = {})
|
25
|
+
# Returns users following followers of the authenticated user
|
26
|
+
#
|
27
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
28
|
+
# @param options [Hash] A customizable set of options.
|
29
|
+
# @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.
|
30
|
+
# @return [Twitter::Cursor]
|
31
|
+
def following_followers_of(*args)
|
32
|
+
cursor_from_response_with_user(:users, Twitter::User, :get, '/users/following_followers_of.json', args)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns Tweets count for a URI
|
36
|
+
#
|
37
|
+
# @note Undocumented
|
38
|
+
# @rate_limited No
|
39
|
+
# @authentication Not required
|
40
|
+
# @return [Integer]
|
41
|
+
# @param uri [String, URI] A URI.
|
42
|
+
# @param options [Hash] A customizable set of options.
|
43
|
+
def tweet_count(uri, options = {})
|
44
|
+
connection = Faraday.new('https://cdn.api.twitter.com', connection_options.merge(:builder => middleware))
|
45
|
+
connection.get('/1/urls/count.json', options.merge(:url => uri.to_s)).body[:count]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,383 @@
|
|
1
|
+
require 'twitter/arguments'
|
2
|
+
require 'twitter/error'
|
3
|
+
require 'twitter/profile_banner'
|
4
|
+
require 'twitter/request'
|
5
|
+
require 'twitter/rest/utils'
|
6
|
+
require 'twitter/settings'
|
7
|
+
require 'twitter/user'
|
8
|
+
require 'twitter/utils'
|
9
|
+
|
10
|
+
module Twitter
|
11
|
+
module REST
|
12
|
+
module Users
|
13
|
+
include Twitter::REST::Utils
|
14
|
+
include Twitter::Utils
|
15
|
+
MAX_USERS_PER_REQUEST = 100
|
16
|
+
|
17
|
+
# Updates the authenticating user's settings.
|
18
|
+
# Or, if no options supplied, returns settings (including current trend, geo and sleep time information) for the authenticating user.
|
19
|
+
#
|
20
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/account/settings
|
21
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/account/settings
|
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 [Twitter::Settings]
|
26
|
+
# @param options [Hash] A customizable set of options.
|
27
|
+
# @option options [Integer] :trend_location_woeid The Yahoo! Where On Earth ID to use as the user's default trend location. Global information is available by using 1 as the WOEID. The woeid must be one of the locations returned by {https://dev.twitter.com/docs/api/1.1/get/trends/available GET trends/available}.
|
28
|
+
# @option options [Boolean, String, Integer] :sleep_time_enabled When set to true, 't' or 1, will enable sleep time for the user. Sleep time is the time when push or SMS notifications should not be sent to the user.
|
29
|
+
# @option options [Integer] :start_sleep_time The hour that sleep time should begin if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
|
30
|
+
# @option options [Integer] :end_sleep_time The hour that sleep time should end if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
|
31
|
+
# @option options [String] :time_zone The timezone dates and times should be displayed in for the user. The timezone must be one of the {http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html Rails TimeZone} names.
|
32
|
+
# @option options [String] :lang The language which Twitter should render in for this user. The language must be specified by the appropriate two letter ISO 639-1 representation. Currently supported languages are provided by {https://dev.twitter.com/docs/api/1.1/get/help/languages GET help/languages}.
|
33
|
+
def settings(options = {})
|
34
|
+
request_method = options.size.zero? ? :get : :post
|
35
|
+
response = send(request_method.to_sym, '/1.1/account/settings.json', options).body
|
36
|
+
# https://dev.twitter.com/issues/59
|
37
|
+
response.update(:trend_location => Array(response[:trend_location]).first)
|
38
|
+
Twitter::Settings.new(response)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the requesting user if authentication was successful, otherwise raises {Twitter::Error::Unauthorized}
|
42
|
+
#
|
43
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/account/verify_credentials
|
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 [Twitter::User] The authenticated user.
|
48
|
+
# @param options [Hash] A customizable set of options.
|
49
|
+
# @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
|
50
|
+
def verify_credentials(options = {})
|
51
|
+
perform_with_object(:get, '/1.1/account/verify_credentials.json', options, Twitter::User)
|
52
|
+
end
|
53
|
+
alias_method :current_user, :verify_credentials
|
54
|
+
|
55
|
+
# Sets which device Twitter delivers updates to for the authenticating user
|
56
|
+
#
|
57
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/account/update_delivery_device
|
58
|
+
# @rate_limited No
|
59
|
+
# @authentication Requires user context
|
60
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
61
|
+
# @return [Twitter::User] The authenticated user.
|
62
|
+
# @param device [String] Must be one of: 'sms', 'none'.
|
63
|
+
# @param options [Hash] A customizable set of options.
|
64
|
+
def update_delivery_device(device, options = {})
|
65
|
+
perform_with_object(:post, '/1.1/account/update_delivery_device.json', options.merge(:device => device), Twitter::User)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Sets values that users are able to set under the "Account" tab of their settings page
|
69
|
+
#
|
70
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile
|
71
|
+
# @note Only the options specified will be updated.
|
72
|
+
# @rate_limited No
|
73
|
+
# @authentication Requires user context
|
74
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
75
|
+
# @return [Twitter::User] The authenticated user.
|
76
|
+
# @param options [Hash] A customizable set of options.
|
77
|
+
# @option options [String] :name Full name associated with the profile. Maximum of 20 characters.
|
78
|
+
# @option options [String] :url URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters.
|
79
|
+
# @option options [String] :location The city or country describing where the user of the account is located. The contents are not normalized or geocoded in any way. Maximum of 30 characters.
|
80
|
+
# @option options [String] :description A description of the user owning the account. Maximum of 160 characters.
|
81
|
+
def update_profile(options = {})
|
82
|
+
perform_with_object(:post, '/1.1/account/update_profile.json', options, Twitter::User)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Updates the authenticating user's profile background image
|
86
|
+
#
|
87
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_background_image
|
88
|
+
# @rate_limited No
|
89
|
+
# @authentication Requires user context
|
90
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
91
|
+
# @return [Twitter::User] The authenticated user.
|
92
|
+
# @param image [File] The background image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. Images with width larger than 2048 pixels will be forcibly scaled down. The image must be provided as raw multipart data, not a URL.
|
93
|
+
# @param options [Hash] A customizable set of options.
|
94
|
+
# @option options [Boolean] :tile Whether or not to tile the background image. If set to true the background image will be displayed tiled. The image will not be tiled otherwise.
|
95
|
+
def update_profile_background_image(image, options = {})
|
96
|
+
perform_with_object(:post, '/1.1/account/update_profile_background_image.json', options.merge(:image => image), Twitter::User)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Sets one or more hex values that control the color scheme of the authenticating user's profile
|
100
|
+
#
|
101
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_colors
|
102
|
+
# @rate_limited No
|
103
|
+
# @authentication Requires user context
|
104
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
105
|
+
# @return [Twitter::User] The authenticated user.
|
106
|
+
# @param options [Hash] A customizable set of options.
|
107
|
+
# @option options [String] :profile_background_color Profile background color.
|
108
|
+
# @option options [String] :profile_text_color Profile text color.
|
109
|
+
# @option options [String] :profile_link_color Profile link color.
|
110
|
+
# @option options [String] :profile_sidebar_fill_color Profile sidebar's background color.
|
111
|
+
# @option options [String] :profile_sidebar_border_color Profile sidebar's border color.
|
112
|
+
def update_profile_colors(options = {})
|
113
|
+
perform_with_object(:post, '/1.1/account/update_profile_colors.json', options, Twitter::User)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Updates the authenticating user's profile image
|
117
|
+
#
|
118
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_image
|
119
|
+
# @note Updates the authenticating user's profile image. Note that this method expects raw multipart data, not a URL to an image.
|
120
|
+
# @note This method asynchronously processes the uploaded file before updating the user's profile image URL. You can either update your local cache the next time you request the user's information, or, at least 5 seconds after uploading the image, ask for the updated URL using GET users/show.
|
121
|
+
# @rate_limited No
|
122
|
+
# @authentication Requires user context
|
123
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
124
|
+
# @return [Twitter::User] The authenticated user.
|
125
|
+
# @param image [File] The avatar image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down. Animated GIFs will be converted to a static GIF of the first frame, removing the animation.
|
126
|
+
# @param options [Hash] A customizable set of options.
|
127
|
+
def update_profile_image(image, options = {})
|
128
|
+
perform_with_object(:post, '/1.1/account/update_profile_image.json', options.merge(:image => image), Twitter::User)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Returns an array of user objects that the authenticating user is blocking
|
132
|
+
#
|
133
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/blocks/list
|
134
|
+
# @rate_limited Yes
|
135
|
+
# @authentication Requires user context
|
136
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
137
|
+
# @return [Array<Twitter::User>] User objects that the authenticating user is blocking.
|
138
|
+
# @param options [Hash] A customizable set of options.
|
139
|
+
# @option options [Integer] :page Specifies the page of results to retrieve.
|
140
|
+
def blocking(options = {})
|
141
|
+
perform_with_cursor(:get, '/1.1/blocks/list.json', options, :users, Twitter::User)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Returns an array of numeric user ids the authenticating user is blocking
|
145
|
+
#
|
146
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/blocks/ids
|
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 [Twitter::Cursor] Numeric user IDs the authenticating user is blocking.
|
151
|
+
# @overload block(options = {})
|
152
|
+
# @param options [Hash] A customizable set of options.
|
153
|
+
def blocked_ids(*args)
|
154
|
+
arguments = Twitter::Arguments.new(args)
|
155
|
+
merge_user!(arguments.options, arguments.pop)
|
156
|
+
perform_with_cursor(:get, '/1.1/blocks/ids.json', arguments.options, :ids)
|
157
|
+
end
|
158
|
+
|
159
|
+
# Returns true if the authenticating user is blocking a target user
|
160
|
+
#
|
161
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/blocks/ids
|
162
|
+
# @rate_limited Yes
|
163
|
+
# @authentication Requires user context
|
164
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
165
|
+
# @return [Boolean] true if the authenticating user is blocking the target user, otherwise false.
|
166
|
+
# @param user [Integer, String, URI, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
167
|
+
# @param options [Hash] A customizable set of options.
|
168
|
+
def block?(user, options = {})
|
169
|
+
user_id = case user
|
170
|
+
when Integer
|
171
|
+
user
|
172
|
+
when String, URI, Addressable::URI
|
173
|
+
user(user).id
|
174
|
+
when Twitter::User
|
175
|
+
user.id
|
176
|
+
end
|
177
|
+
blocked_ids(options).collect(&:to_i).include?(user_id)
|
178
|
+
end
|
179
|
+
|
180
|
+
# Blocks the users specified by the authenticating user
|
181
|
+
#
|
182
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/blocks/create
|
183
|
+
# @note Destroys a friendship to the blocked user if it exists.
|
184
|
+
# @rate_limited Yes
|
185
|
+
# @authentication Requires user context
|
186
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
187
|
+
# @return [Array<Twitter::User>] The blocked users.
|
188
|
+
# @overload block(*users)
|
189
|
+
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
|
190
|
+
# @overload block(*users, options)
|
191
|
+
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
|
192
|
+
# @param options [Hash] A customizable set of options.
|
193
|
+
def block(*args)
|
194
|
+
parallel_user_objects_from_response(:post, '/1.1/blocks/create.json', args)
|
195
|
+
end
|
196
|
+
|
197
|
+
# Un-blocks the users specified by the authenticating user
|
198
|
+
#
|
199
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/blocks/destroy
|
200
|
+
# @rate_limited No
|
201
|
+
# @authentication Requires user context
|
202
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
203
|
+
# @return [Array<Twitter::User>] The un-blocked users.
|
204
|
+
# @overload unblock(*users)
|
205
|
+
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
|
206
|
+
# @overload unblock(*users, options)
|
207
|
+
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
|
208
|
+
# @param options [Hash] A customizable set of options.
|
209
|
+
def unblock(*args)
|
210
|
+
parallel_user_objects_from_response(:post, '/1.1/blocks/destroy.json', args)
|
211
|
+
end
|
212
|
+
|
213
|
+
# Returns extended information for up to 100 users
|
214
|
+
#
|
215
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/users/lookup
|
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 [Array<Twitter::User>] The requested users.
|
220
|
+
# @overload users(*users)
|
221
|
+
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
|
222
|
+
# @overload users(*users, options)
|
223
|
+
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
|
224
|
+
# @param options [Hash] A customizable set of options.
|
225
|
+
# @option options [Symbol, String] :method Requests users via a GET request instead of the standard POST request if set to ':get'.
|
226
|
+
# @option options [Boolean] :include_entities The tweet entities node will be disincluded when set to false.
|
227
|
+
def users(*args)
|
228
|
+
arguments = Twitter::Arguments.new(args)
|
229
|
+
request_method = arguments.options.delete(:method) || :post
|
230
|
+
parallel_map(arguments.each_slice(MAX_USERS_PER_REQUEST)) do |users|
|
231
|
+
perform_with_objects(request_method, '/1.1/users/lookup.json', merge_users(arguments.options, users), Twitter::User)
|
232
|
+
end.flatten
|
233
|
+
end
|
234
|
+
|
235
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/users/show
|
236
|
+
# @rate_limited Yes
|
237
|
+
# @authentication Requires user context
|
238
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
239
|
+
# @return [Twitter::User] The requested user.
|
240
|
+
# @overload user(options = {})
|
241
|
+
# Returns extended information for the authenticated user
|
242
|
+
#
|
243
|
+
# @param options [Hash] A customizable set of options.
|
244
|
+
# @option options [Boolean] :include_entities The tweet entities node will be disincluded when set to false.
|
245
|
+
# @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
|
246
|
+
# @overload user(user, options = {})
|
247
|
+
# Returns extended information for a given user
|
248
|
+
#
|
249
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
250
|
+
# @param options [Hash] A customizable set of options.
|
251
|
+
# @option options [Boolean] :include_entities The tweet entities node will be disincluded when set to false.
|
252
|
+
# @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
|
253
|
+
def user(*args)
|
254
|
+
arguments = Twitter::Arguments.new(args)
|
255
|
+
if arguments.last
|
256
|
+
merge_user!(arguments.options, arguments.pop)
|
257
|
+
perform_with_object(:get, '/1.1/users/show.json', arguments.options, Twitter::User)
|
258
|
+
else
|
259
|
+
verify_credentials(arguments.options)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
# Returns true if the specified user exists
|
264
|
+
#
|
265
|
+
# @rate_limited Yes
|
266
|
+
# @authentication Requires user context
|
267
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
268
|
+
# @return [Boolean] true if the user exists, otherwise false.
|
269
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
270
|
+
def user?(user, options = {})
|
271
|
+
merge_user!(options, user)
|
272
|
+
get('/1.1/users/show.json', options)
|
273
|
+
true
|
274
|
+
rescue Twitter::Error::NotFound
|
275
|
+
false
|
276
|
+
end
|
277
|
+
|
278
|
+
# Returns users that match the given query
|
279
|
+
#
|
280
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/users/search
|
281
|
+
# @rate_limited Yes
|
282
|
+
# @authentication Requires user context
|
283
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
284
|
+
# @return [Array<Twitter::User>]
|
285
|
+
# @param query [String] The search query to run against people search.
|
286
|
+
# @param options [Hash] A customizable set of options.
|
287
|
+
# @option options [Integer] :count The number of people to retrieve. Maxiumum of 20 allowed per page.
|
288
|
+
# @option options [Integer] :page Specifies the page of results to retrieve.
|
289
|
+
def user_search(query, options = {})
|
290
|
+
perform_with_objects(:get, '/1.1/users/search.json', options.merge(:q => query), Twitter::User)
|
291
|
+
end
|
292
|
+
|
293
|
+
# Returns an array of users that the specified user can contribute to
|
294
|
+
#
|
295
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/users/contributees
|
296
|
+
# @rate_limited Yes
|
297
|
+
# @authentication Requires user context
|
298
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
299
|
+
# @return [Array<Twitter::User>]
|
300
|
+
# @overload contributees(options = {})
|
301
|
+
# @param options [Hash] A customizable set of options.
|
302
|
+
# @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
|
303
|
+
# @overload contributees(user, options = {})
|
304
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
305
|
+
# @param options [Hash] A customizable set of options.
|
306
|
+
# @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
|
307
|
+
def contributees(*args)
|
308
|
+
user_objects_from_response(:get, '/1.1/users/contributees.json', args)
|
309
|
+
end
|
310
|
+
|
311
|
+
# Returns an array of users who can contribute to the specified account
|
312
|
+
#
|
313
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/users/contributors
|
314
|
+
# @rate_limited Yes
|
315
|
+
# @authentication Requires user context
|
316
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
317
|
+
# @return [Array<Twitter::User>]
|
318
|
+
# @overload contributors(options = {})
|
319
|
+
# @param options [Hash] A customizable set of options.
|
320
|
+
# @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
|
321
|
+
# @overload contributors(user, options = {})
|
322
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
323
|
+
# @param options [Hash] A customizable set of options.
|
324
|
+
# @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
|
325
|
+
def contributors(*args)
|
326
|
+
user_objects_from_response(:get, '/1.1/users/contributors.json', args)
|
327
|
+
end
|
328
|
+
|
329
|
+
# Removes the authenticating user's profile banner image
|
330
|
+
#
|
331
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/account/remove_profile_banner
|
332
|
+
# @rate_limited No
|
333
|
+
# @authentication Requires user context
|
334
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
335
|
+
# @return [nil]
|
336
|
+
# @param options [Hash] A customizable set of options.
|
337
|
+
def remove_profile_banner(options = {})
|
338
|
+
post('/1.1/account/remove_profile_banner.json', options).body
|
339
|
+
true
|
340
|
+
end
|
341
|
+
deprecate_alias :profile_banner_remove, :remove_profile_banner
|
342
|
+
|
343
|
+
# Updates the authenticating user's profile banner image
|
344
|
+
#
|
345
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_banner
|
346
|
+
# @note Uploads a profile banner on behalf of the authenticating user. For best results, upload an <5MB image that is exactly 1252px by 626px. Images will be resized for a number of display options. Users with an uploaded profile banner will have a profile_banner_url node in their Users objects. More information about sizing variations can be found in User Profile Images and Banners.
|
347
|
+
# @note Profile banner images are processed asynchronously. The profile_banner_url and its variant sizes will not necessary be available directly after upload.
|
348
|
+
# @rate_limited No
|
349
|
+
# @authentication Requires user context
|
350
|
+
# @raise [Twitter::Error::BadRequest] Error raised when either an image was not provided or the image data could not be processed.
|
351
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
352
|
+
# @raise [Twitter::Error::UnprocessableEntity] Error raised when the image could not be resized or is too large.
|
353
|
+
# @return [nil]
|
354
|
+
# @param banner [File] The Base64-encoded or raw image data being uploaded as the user's new profile banner.
|
355
|
+
# @param options [Hash] A customizable set of options.
|
356
|
+
# @option options [Integer] :width The width of the preferred section of the image being uploaded in pixels. Use with height, offset_left, and offset_top to select the desired region of the image to use.
|
357
|
+
# @option options [Integer] :height The height of the preferred section of the image being uploaded in pixels. Use with width, offset_left, and offset_top to select the desired region of the image to use.
|
358
|
+
# @option options [Integer] :offset_left The number of pixels by which to offset the uploaded image from the left. Use with height, width, and offset_top to select the desired region of the image to use.
|
359
|
+
# @option options [Integer] :offset_top The number of pixels by which to offset the uploaded image from the top. Use with height, width, and offset_left to select the desired region of the image to use.
|
360
|
+
def update_profile_banner(banner, options = {})
|
361
|
+
post('/1.1/account/update_profile_banner.json', options.merge(:banner => banner)).body
|
362
|
+
true
|
363
|
+
end
|
364
|
+
|
365
|
+
# Returns the available size variations of the specified user's profile banner.
|
366
|
+
#
|
367
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/users/profile_banner
|
368
|
+
# @note If the user has not uploaded a profile banner, a HTTP 404 will be served instead.
|
369
|
+
# @rate_limited Yes
|
370
|
+
# @authentication Requires user context
|
371
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
372
|
+
# @return [Twitter::ProfileBanner]
|
373
|
+
# @overload profile_banner(options = {})
|
374
|
+
# @overload profile_banner(user, options = {})
|
375
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
376
|
+
def profile_banner(*args)
|
377
|
+
arguments = Twitter::Arguments.new(args)
|
378
|
+
merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
|
379
|
+
perform_with_object(:get, '/1.1/users/profile_banner.json', arguments.options, Twitter::ProfileBanner)
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|