Module: Twitter::REST::Tweets
Constant Summary collapse
- MAX_TWEETS_PER_REQUEST =
100
Constants included from Utils
Instance Method Summary collapse
-
#destroy_status(*args) ⇒ Array<Twitter::Tweet>
(also: #destroy_tweet)
Destroys the specified Tweets.
-
#oembed(tweet, options = {}) ⇒ Twitter::OEmbed
Returns oEmbed for a Tweet.
-
#oembeds(*args) ⇒ Array<Twitter::OEmbed>
Returns oEmbeds for Tweets.
-
#retweet(*args) ⇒ Array<Twitter::Tweet>
Retweets the specified Tweets as the authenticating user.
-
#retweet!(*args) ⇒ Array<Twitter::Tweet>
Retweets the specified Tweets as the authenticating user and raises an error if one has already been retweeted.
-
#retweeters_ids(*args) ⇒ Twitter::Cursor
Returns a collection of up to 100 user IDs belonging to users who have retweeted the tweet specified by the id parameter.
-
#retweeters_of(tweet, options = {}) ⇒ Array
Show up to 100 users who retweeted the Tweet.
-
#retweets(tweet, options = {}) ⇒ Array<Twitter::Tweet>
Returns up to 100 of the first retweets of a given tweet.
-
#status(tweet, options = {}) ⇒ Twitter::Tweet
Returns a Tweet.
-
#statuses(*args) ⇒ Array<Twitter::Tweet>
Returns Tweets.
-
#unretweet(*args) ⇒ Array<Twitter::Tweet>
Untweets a retweeted status as the authenticating user.
-
#update(status, options = {}) ⇒ Twitter::Tweet
Updates the authenticating user's status.
-
#update!(status, options = {}) ⇒ Twitter::Tweet
Updates the authenticating user's status.
-
#update_with_media(status, media, options = {}) ⇒ Twitter::Tweet
Updates the authenticating user's status with media.
Methods included from Utils
Instance Method Details
#destroy_status(*tweets) ⇒ Array<Twitter::Tweet> #destroy_status(*tweets, options) ⇒ Array<Twitter::Tweet> Also known as: destroy_tweet
The authenticating user must be the author of the specified Tweets.
Destroys the specified Tweets
100 101 102 103 104 105 |
# File 'lib/twitter/rest/tweets.rb', line 100 def destroy_status(*args) arguments = Twitter::Arguments.new(args) pmap(arguments) do |tweet| perform_post_with_object("/1.1/statuses/destroy/#{extract_id(tweet)}.json", arguments., Twitter::Tweet) end end |
#oembed(tweet, options = {}) ⇒ Twitter::OEmbed
Returns oEmbed for a Tweet
250 251 252 253 254 |
# File 'lib/twitter/rest/tweets.rb', line 250 def (tweet, = {}) = .dup [:id] = extract_id(tweet) perform_get_with_object("/1.1/statuses/oembed.json", , Twitter::OEmbed) end |
#oembed(*tweets) ⇒ Array<Twitter::OEmbed> #oembed(*tweets, options) ⇒ Array<Twitter::OEmbed>
Returns oEmbeds for Tweets
275 276 277 278 279 280 |
# File 'lib/twitter/rest/tweets.rb', line 275 def (*args) arguments = Twitter::Arguments.new(args) pmap(arguments) do |tweet| (extract_id(tweet), arguments.) end end |
#retweet(*tweets) ⇒ Array<Twitter::Tweet> #retweet(*tweets, options) ⇒ Array<Twitter::Tweet>
Retweets the specified Tweets as the authenticating user
173 174 175 176 177 178 179 180 |
# File 'lib/twitter/rest/tweets.rb', line 173 def retweet(*args) arguments = Twitter::Arguments.new(args) pmap(arguments) do |tweet| post_retweet(extract_id(tweet), arguments.) rescue Twitter::Error::AlreadyRetweeted, Twitter::Error::NotFound next end.compact end |
#retweet!(*tweets) ⇒ Array<Twitter::Tweet> #retweet!(*tweets, options) ⇒ Array<Twitter::Tweet>
Retweets the specified Tweets as the authenticating user and raises an error if one has already been retweeted
197 198 199 200 201 202 |
# File 'lib/twitter/rest/tweets.rb', line 197 def retweet!(*args) arguments = Twitter::Arguments.new(args) pmap(arguments) do |tweet| post_retweet(extract_id(tweet), arguments.) end.compact end |
#retweeters_ids(options) ⇒ Twitter::Cursor #retweeters_ids(id, options = {}) ⇒ Twitter::Cursor
Returns a collection of up to 100 user IDs belonging to users who have retweeted the tweet specified by the id parameter.
294 295 296 297 298 |
# File 'lib/twitter/rest/tweets.rb', line 294 def retweeters_ids(*args) arguments = Twitter::Arguments.new(args) arguments.[:id] ||= extract_id(arguments.first) perform_get_with_cursor("/1.1/statuses/retweeters/ids.json", arguments., :ids) end |
#retweeters_of(tweet, options = {}) ⇒ Array
Show up to 100 users who retweeted the Tweet
45 46 47 48 49 50 |
# File 'lib/twitter/rest/tweets.rb', line 45 def retweeters_of(tweet, = {}) = .dup ids_only = !!.delete(:ids_only) retweeters = retweets(tweet, ).collect(&:user) ids_only ? retweeters.collect(&:id) : retweeters end |
#retweets(tweet, options = {}) ⇒ Array<Twitter::Tweet>
Returns up to 100 of the first retweets of a given tweet
29 30 31 |
# File 'lib/twitter/rest/tweets.rb', line 29 def retweets(tweet, = {}) perform_get_with_objects("/1.1/statuses/retweets/#{extract_id(tweet)}.json", , Twitter::Tweet) end |
#status(tweet, options = {}) ⇒ Twitter::Tweet
Returns a Tweet
63 64 65 |
# File 'lib/twitter/rest/tweets.rb', line 63 def status(tweet, = {}) perform_get_with_object("/1.1/statuses/show/#{extract_id(tweet)}.json", , Twitter::Tweet) end |
#statuses(*tweets) ⇒ Array<Twitter::Tweet> #statuses(*tweets, options) ⇒ Array<Twitter::Tweet>
Returns Tweets
79 80 81 82 83 84 |
# File 'lib/twitter/rest/tweets.rb', line 79 def statuses(*args) arguments = Twitter::Arguments.new(args) flat_pmap(arguments.each_slice(MAX_TWEETS_PER_REQUEST)) do |tweets| perform_post_with_objects("/1.1/statuses/lookup.json", arguments..merge(id: tweets.collect { |u| extract_id(u) }.join(",")), Twitter::Tweet) end end |
#unretweet(*tweets) ⇒ Array<Twitter::Tweet> #unretweet(*tweets, options) ⇒ Array<Twitter::Tweet>
Untweets a retweeted status as the authenticating user
313 314 315 316 317 318 319 320 |
# File 'lib/twitter/rest/tweets.rb', line 313 def unretweet(*args) arguments = Twitter::Arguments.new(args) pmap(arguments) do |tweet| post_unretweet(extract_id(tweet), arguments.) rescue Twitter::Error::NotFound next end.compact end |
#update(status, options = {}) ⇒ Twitter::Tweet
A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.
Updates the authenticating user's status
127 128 129 130 131 |
# File 'lib/twitter/rest/tweets.rb', line 127 def update(status, = {}) update!(status, ) rescue Twitter::Error::DuplicateStatus user_timeline(count: 1).first end |
#update!(status, options = {}) ⇒ Twitter::Tweet
A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.
Updates the authenticating user's status
153 154 155 156 157 158 |
# File 'lib/twitter/rest/tweets.rb', line 153 def update!(status, = {}) hash = .dup hash[:in_reply_to_status_id] = hash.delete(:in_reply_to_status).id unless hash[:in_reply_to_status].nil? hash[:place_id] = hash.delete(:place).woeid unless hash[:place].nil? perform_post_with_object("/1.1/statuses/update.json", hash.merge(status:), Twitter::Tweet) end |
#update_with_media(status, media, options = {}) ⇒ Twitter::Tweet
A status update with text/media identical to the authenticating user's current status will NOT be ignored
Updates the authenticating user's status with media
224 225 226 227 228 229 230 |
# File 'lib/twitter/rest/tweets.rb', line 224 def update_with_media(status, media, = {}) = .dup media_ids = pmap(array_wrap(media)) do |medium| upload(medium)[:media_id] end update!(status, .merge(media_ids: media_ids.join(","))) end |