Module: Twitter::REST::Tweets
Overview
Methods for working with tweets
Constant Summary collapse
- MAX_TWEETS_PER_REQUEST =
Maximum 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 and raises an error if already retweeted.
-
#retweeters_ids(*args) ⇒ Twitter::Cursor
Returns up to 100 user IDs who retweeted the tweet.
-
#retweeters_of(tweet, options = {}) ⇒ Array
Shows 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, raising an error on duplicate.
-
#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
118 119 120 121 122 123 |
# File 'lib/twitter/rest/tweets.rb', line 118 def destroy_status(*args) arguments = Arguments.new(args) pmap(arguments) do |tweet| perform_post_with_object("/1.1/statuses/destroy/#{extract_id(tweet)}.json", arguments., Tweet) end end |
#oembed(tweet, options = {}) ⇒ Twitter::OEmbed
Returns oEmbed for a Tweet
286 287 288 289 290 |
# File 'lib/twitter/rest/tweets.rb', line 286 def (tweet, = {}) = .dup [:id] = extract_id(tweet) perform_get_with_object("/1.1/statuses/oembed.json", , OEmbed) end |
#oembed(*tweets) ⇒ Array<Twitter::OEmbed> #oembed(*tweets, options) ⇒ Array<Twitter::OEmbed>
Returns oEmbeds for Tweets
314 315 316 317 318 319 |
# File 'lib/twitter/rest/tweets.rb', line 314 def (*args) arguments = Arguments.new(args) pmap(arguments) do |tweet| (tweet, arguments.) end end |
#retweet(*tweets) ⇒ Array<Twitter::Tweet> #retweet(*tweets, options) ⇒ Array<Twitter::Tweet>
Retweets the specified Tweets as the authenticating user
202 203 204 205 206 207 208 209 |
# File 'lib/twitter/rest/tweets.rb', line 202 def retweet(*args) arguments = Arguments.new(args) pmap(arguments) do |tweet| post_retweet(extract_id(tweet), arguments.) rescue Error::AlreadyRetweeted, Error::NotFound nil end.compact end |
#retweet!(*tweets) ⇒ Array<Twitter::Tweet> #retweet!(*tweets, options) ⇒ Array<Twitter::Tweet>
Retweets the specified Tweets and raises an error if already retweeted
229 230 231 232 233 234 |
# File 'lib/twitter/rest/tweets.rb', line 229 def retweet!(*args) arguments = Arguments.new(args) pmap(arguments) do |tweet| post_retweet(extract_id(tweet), arguments.) end end |
#retweeters_ids(options) ⇒ Twitter::Cursor #retweeters_ids(id, options = {}) ⇒ Twitter::Cursor
Returns up to 100 user IDs who retweeted the tweet
336 337 338 339 340 |
# File 'lib/twitter/rest/tweets.rb', line 336 def retweeters_ids(*args) arguments = 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
Shows up to 100 users who retweeted the Tweet
54 55 56 57 58 59 |
# File 'lib/twitter/rest/tweets.rb', line 54 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
35 36 37 |
# File 'lib/twitter/rest/tweets.rb', line 35 def retweets(tweet, = {}) perform_get_with_objects("/1.1/statuses/retweets/#{extract_id(tweet)}.json", , Tweet) end |
#status(tweet, options = {}) ⇒ Twitter::Tweet
Returns a Tweet
75 76 77 |
# File 'lib/twitter/rest/tweets.rb', line 75 def status(tweet, = {}) perform_get_with_object("/1.1/statuses/show/#{extract_id(tweet)}.json", , Tweet) end |
#statuses(*tweets) ⇒ Array<Twitter::Tweet> #statuses(*tweets, options) ⇒ Array<Twitter::Tweet>
Returns Tweets
94 95 96 97 98 99 |
# File 'lib/twitter/rest/tweets.rb', line 94 def statuses(*args) arguments = 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(",")), Tweet) end end |
#unretweet(*tweets) ⇒ Array<Twitter::Tweet> #unretweet(*tweets, options) ⇒ Array<Twitter::Tweet>
Untweets a retweeted status as the authenticating user
358 359 360 361 362 363 364 365 |
# File 'lib/twitter/rest/tweets.rb', line 358 def unretweet(*args) arguments = Arguments.new(args) pmap(arguments) do |tweet| post_unretweet(extract_id(tweet), arguments.) rescue Error::NotFound nil end.compact end |
#update(status, options = {}) ⇒ Twitter::Tweet
Duplicate statuses are ignored to prevent duplicates.
Updates the authenticating user's status
151 152 153 154 155 |
# File 'lib/twitter/rest/tweets.rb', line 151 def update(status, = {}) update!(status, ) rescue Error::DuplicateStatus user_timeline(count: 1).first # steep:ignore NoMethod end |
#update!(status, options = {}) ⇒ Twitter::Tweet
Updates the authenticating user's status, raising an error on duplicate
179 180 181 182 183 184 |
# File 'lib/twitter/rest/tweets.rb', line 179 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:), Tweet) end |
#update_with_media(status, media, options = {}) ⇒ Twitter::Tweet
Updates the authenticating user's status with media
258 259 260 261 262 263 |
# File 'lib/twitter/rest/tweets.rb', line 258 def update_with_media(status, media, = {}) media_ids = pmap(array_wrap(media)) do |medium| upload(medium).fetch(:media_id) end update!(status, .merge(media_ids: media_ids.join(","))) end |