Module: Twitter::REST::Tweets
Constant Summary collapse
- MAX_TWEETS_PER_REQUEST =
100
Constants included from Utils
Utils::DEFAULT_CURSOR, Utils::URI_SUBSTRING
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.
-
#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
97 98 99 100 101 102 |
# File 'lib/twitter/rest/tweets.rb', line 97 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
254 255 256 257 |
# File 'lib/twitter/rest/tweets.rb', line 254 def (tweet, = {}) [: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
278 279 280 281 282 283 |
# File 'lib/twitter/rest/tweets.rb', line 278 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
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/twitter/rest/tweets.rb', line 174 def retweet(*args) arguments = Twitter::Arguments.new(args) pmap(arguments) do |tweet| begin post_retweet(extract_id(tweet), arguments.) rescue Twitter::Error::AlreadyRetweeted, Twitter::Error::NotFound next end 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
200 201 202 203 204 205 |
# File 'lib/twitter/rest/tweets.rb', line 200 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.
297 298 299 300 301 |
# File 'lib/twitter/rest/tweets.rb', line 297 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
43 44 45 46 47 |
# File 'lib/twitter/rest/tweets.rb', line 43 def retweeters_of(tweet, = {}) 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
27 28 29 |
# File 'lib/twitter/rest/tweets.rb', line 27 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
60 61 62 |
# File 'lib/twitter/rest/tweets.rb', line 60 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
76 77 78 79 80 81 |
# File 'lib/twitter/rest/tweets.rb', line 76 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 |
#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
154 155 156 157 158 159 |
# File 'lib/twitter/rest/tweets.rb', line 154 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: 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
228 229 230 231 232 233 234 |
# File 'lib/twitter/rest/tweets.rb', line 228 def update_with_media(status, media, = {}) raise(Twitter::Error::UnacceptableIO.new) unless media.respond_to?(:to_io) 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_with_media.json', hash.merge('media[]' => media, 'status' => status), Twitter::Tweet) end |