Module: Twitter::REST::Tweets

Includes:
Utils, Utils
Included in:
API
Defined in:
lib/twitter/rest/tweets.rb

Constant Summary

Constant Summary

Constants included from Utils

Utils::DEFAULT_CURSOR, Utils::URI_SUBSTRING

Instance Method Summary (collapse)

Methods included from Utils

flat_pmap, pmap, pmap_with_index

Instance Method Details

- (Array<Twitter::Tweet>) destroy_status(*tweets) - (Array<Twitter::Tweet>) destroy_status(*tweets, options) Also known as: destroy_tweet

Note:

The authenticating user must be the author of the specified Tweets.

Destroys the specified Tweets

Overloads:

  • - (Array<Twitter::Tweet>) destroy_status(*tweets)

    Parameters:

  • - (Array<Twitter::Tweet>) destroy_status(*tweets, options)

    Parameters:

    • tweets (Enumerable<Integer, String, URI, Twitter::Tweet>)

      A collection of Tweet IDs, URIs, or objects.

    • options (Hash)

      A customizable set of options.

    Options Hash (options):

    • :trim_user (Boolean, String, Integer)

      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.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



94
95
96
# File 'lib/twitter/rest/tweets.rb', line 94

def destroy_status(*args)
  parallel_tweets_from_response(:post, '/1.1/statuses/destroy', args)
end

- (Twitter::OEmbed) oembed(tweet, options = {})

Returns oEmbed for a Tweet

Parameters:

  • tweet (Integer, String, URI, Twitter::Tweet)

    A Tweet ID, URI, or object.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :maxwidth (Integer)

    The maximum width in pixels that the embed should be rendered at. This value is constrained to be between 250 and 550 pixels.

  • :hide_media (Boolean, String, Integer)

    Specifies whether the embedded Tweet should automatically expand images which were uploaded via POST statuses/update_with_media. When set to either true, t or 1 images will not be expanded. Defaults to false.

  • :hide_thread (Boolean, String, Integer)

    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.

  • :omit_script (Boolean, String, Integer)

    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.

  • :align (String)

    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.

  • :related (String)

    A value for the TWT related parameter, as described in Web Intents. This value will be forwarded to all Web Intents calls.

  • :lang (String)

    Language code for the rendered embed. This will affect the text and localization of the rendered HTML.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



239
240
241
242
# File 'lib/twitter/rest/tweets.rb', line 239

def oembed(tweet, options = {})
  options[:id] = extract_id(tweet)
  perform_with_object(:get, '/1.1/statuses/oembed.json', options, Twitter::OEmbed)
end

- (Array<Twitter::OEmbed>) oembed(*tweets) - (Array<Twitter::OEmbed>) oembed(*tweets, options)

Returns oEmbeds for Tweets

Overloads:

  • - (Array<Twitter::OEmbed>) oembed(*tweets)

    Parameters:

  • - (Array<Twitter::OEmbed>) oembed(*tweets, options)

    Parameters:

    • tweets (Enumerable<Integer, String, URI, Twitter::Tweet>)

      A collection of Tweet IDs, URIs, or objects.

    • options (Hash)

      A customizable set of options.

    Options Hash (options):

    • :maxwidth (Integer)

      The maximum width in pixels that the embed should be rendered at. This value is constrained to be between 250 and 550 pixels.

    • :hide_media (Boolean, String, Integer)

      Specifies whether the embedded Tweet should automatically expand images which were uploaded via POST statuses/update_with_media. When set to either true, t or 1 images will not be expanded. Defaults to false.

    • :hide_thread (Boolean, String, Integer)

      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.

    • :omit_script (Boolean, String, Integer)

      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.

    • :align (String)

      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.

    • :related (String)

      A value for the TWT related parameter, as described in Web Intents. This value will be forwarded to all Web Intents calls.

    • :lang (String)

      Language code for the rendered embed. This will affect the text and localization of the rendered HTML.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



263
264
265
266
267
268
# File 'lib/twitter/rest/tweets.rb', line 263

def oembeds(*args)
  arguments = Twitter::Arguments.new(args)
  pmap(arguments) do |tweet|
    oembed(extract_id(tweet), arguments.options)
  end
end

- (Array<Twitter::Tweet>) retweet(*tweets) - (Array<Twitter::Tweet>) retweet(*tweets, options)

Retweets the specified Tweets as the authenticating user

Overloads:

  • - (Array<Twitter::Tweet>) retweet(*tweets)

    Parameters:

  • - (Array<Twitter::Tweet>) retweet(*tweets, options)

    Parameters:

    • tweets (Enumerable<Integer, String, URI, Twitter::Tweet>)

      A collection of Tweet IDs, URIs, or objects.

    • options (Hash)

      A customizable set of options.

    Options Hash (options):

    • :trim_user (Boolean, String, Integer)

      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.

Returns:

  • (Array<Twitter::Tweet>)

    The original tweets with retweet details embedded.

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



164
165
166
167
168
169
170
171
172
173
# File 'lib/twitter/rest/tweets.rb', line 164

def retweet(*args)
  arguments = Twitter::Arguments.new(args)
  pmap(arguments) do |tweet|
    begin
      post_retweet(extract_id(tweet), arguments.options)
    rescue Twitter::Error::AlreadyRetweeted
      next
    end
  end.compact
end

- (Array<Twitter::Tweet>) retweet!(*tweets) - (Array<Twitter::Tweet>) retweet!(*tweets, options)

Retweets the specified Tweets as the authenticating user and raises an error if one has already been retweeted

Overloads:

  • - (Array<Twitter::Tweet>) retweet!(*tweets)

    Parameters:

  • - (Array<Twitter::Tweet>) retweet!(*tweets, options)

    Parameters:

    • tweets (Enumerable<Integer, String, URI, Twitter::Tweet>)

      A collection of Tweet IDs, URIs, or objects.

    • options (Hash)

      A customizable set of options.

    Options Hash (options):

    • :trim_user (Boolean, String, Integer)

      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.

Returns:

  • (Array<Twitter::Tweet>)

    The original tweets with retweet details embedded.

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



189
190
191
192
193
194
# File 'lib/twitter/rest/tweets.rb', line 189

def retweet!(*args)
  arguments = Twitter::Arguments.new(args)
  pmap(arguments) do |tweet|
    post_retweet(extract_id(tweet), arguments.options)
  end.compact
end

- (Twitter::Cursor) retweeters_ids(options) - (Twitter::Cursor) retweeters_ids(id, options = {})

Returns a collection of up to 100 user IDs belonging to users who have retweeted the tweet specified by the id parameter.

Overloads:

  • - (Twitter::Cursor) retweeters_ids(options)

    Parameters:

    • options (Hash)

      A customizable set of options.

  • - (Twitter::Cursor) retweeters_ids(id, options = {})

    Parameters:

    • tweet (Integer, String, URI, Twitter::Tweet)

      A Tweet ID, URI, or object.

    • options (Hash) (defaults to: {})

      A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Required



282
283
284
285
286
# File 'lib/twitter/rest/tweets.rb', line 282

def retweeters_ids(*args)
  arguments = Twitter::Arguments.new(args)
  arguments.options[:id] ||= extract_id(arguments.first)
  perform_with_cursor(:get, '/1.1/statuses/retweeters/ids.json', arguments.options, :ids)
end

- (Array) retweeters_of(tweet, options = {})

Show up to 100 users who retweeted the Tweet

Parameters:

  • tweet (Integer, String, URI, Twitter::Tweet)

    A Tweet ID, URI, or object.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :count (Integer)

    Specifies the number of records to retrieve. Must be less than or equal to 100.

  • :trim_user (Boolean, String, Integer)

    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.

  • :ids_only (Boolean) — default: 'false'

    Only return user ids instead of full user objects.

Returns:

  • (Array)

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



42
43
44
45
46
# File 'lib/twitter/rest/tweets.rb', line 42

def retweeters_of(tweet, options = {})
  ids_only = !!options.delete(:ids_only)
  retweeters = retweets(tweet, options).collect(&:user)
  ids_only ? retweeters.collect(&:id) : retweeters
end

- (Array<Twitter::Tweet>) retweets(tweet, options = {})

Returns up to 100 of the first retweets of a given tweet

Parameters:

  • tweet (Integer, String, URI, Twitter::Tweet)

    A Tweet ID, URI, or object.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :count (Integer)

    Specifies the number of records to retrieve. Must be less than or equal to 100.

  • :trim_user (Boolean, String, Integer)

    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.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



26
27
28
# File 'lib/twitter/rest/tweets.rb', line 26

def retweets(tweet, options = {})
  perform_with_objects(:get, "/1.1/statuses/retweets/#{extract_id(tweet)}.json", options, Twitter::Tweet)
end

- (Twitter::Tweet) status(tweet, options = {})

Returns a Tweet

Parameters:

  • tweet (Integer, String, URI, Twitter::Tweet)

    A Tweet ID, URI, or object.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :trim_user (Boolean, String, Integer)

    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.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



59
60
61
# File 'lib/twitter/rest/tweets.rb', line 59

def status(tweet, options = {})
  perform_with_object(:get, "/1.1/statuses/show/#{extract_id(tweet)}.json", options, Twitter::Tweet)
end

- (Array<Twitter::Tweet>) statuses(*tweets) - (Array<Twitter::Tweet>) statuses(*tweets, options)

Returns Tweets

Overloads:

  • - (Array<Twitter::Tweet>) statuses(*tweets)

    Parameters:

  • - (Array<Twitter::Tweet>) statuses(*tweets, options)

    Parameters:

    • tweets (Enumerable<Integer, String, URI, Twitter::Tweet>)

      A collection of Tweet IDs, URIs, or objects.

    • options (Hash)

      A customizable set of options.

    Options Hash (options):

    • :trim_user (Boolean, String, Integer)

      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.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



76
77
78
# File 'lib/twitter/rest/tweets.rb', line 76

def statuses(*args)
  parallel_tweets_from_response(:get, '/1.1/statuses/show', args)
end

- (Twitter::Tweet) update(status, options = {})

Note:

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

Parameters:

  • status (String)

    The text of your status update, up to 140 characters.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :in_reply_to_status (Twitter::Tweet)

    An existing status that the update is in reply to.

  • :in_reply_to_status_id (Integer)

    The ID of an existing status that the update is in reply to.

  • :lat (Float)

    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.

  • :long (Float)

    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.

  • :place (Twitter::Place)

    A place in the world. These can be retrieved from PlacesAndGeo#reverse_geocode.

  • :place_id (String)

    A place in the world. These IDs can be retrieved from PlacesAndGeo#reverse_geocode.

  • :display_coordinates (String)

    Whether or not to put a pin on the exact coordinates a tweet has been sent from.

  • :trim_user (Boolean, String, Integer)

    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.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



119
120
121
122
123
# File 'lib/twitter/rest/tweets.rb', line 119

def update(status, options = {})
  update!(status, options)
rescue Twitter::Error::DuplicateStatus
  user_timeline(:count => 1).first
end

- (Twitter::Tweet) update!(status, options = {})

Note:

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

Parameters:

  • status (String)

    The text of your status update, up to 140 characters.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :in_reply_to_status (Twitter::Tweet)

    An existing status that the update is in reply to.

  • :in_reply_to_status_id (Integer)

    The ID of an existing status that the update is in reply to.

  • :lat (Float)

    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.

  • :long (Float)

    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.

  • :place (Twitter::Place)

    A place in the world. These can be retrieved from PlacesAndGeo#reverse_geocode.

  • :place_id (String)

    A place in the world. These IDs can be retrieved from PlacesAndGeo#reverse_geocode.

  • :display_coordinates (String)

    Whether or not to put a pin on the exact coordinates a tweet has been sent from.

  • :trim_user (Boolean, String, Integer)

    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.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



144
145
146
147
148
149
# File 'lib/twitter/rest/tweets.rb', line 144

def update!(status, options = {})
  hash = options.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_with_object(:post, '/1.1/statuses/update.json', hash.merge(:status => status), Twitter::Tweet)
end

- (Twitter::Tweet) update_with_media(status, media, options = {})

Note:

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

Parameters:

  • status (String)

    The text of your status update, up to 140 characters.

  • media (File, Hash)

    A File object with your picture (PNG, JPEG or GIF)

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :possibly_sensitive (Boolean, String, Integer)

    Set to true for content which may not be suitable for every audience.

  • :in_reply_to_status (Twitter::Tweet)

    An existing status that the update is in reply to.

  • :in_reply_to_status_id (Integer)

    The ID of an existing Tweet that the update is in reply to.

  • :lat (Float)

    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.

  • :long (Float)

    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.

  • :place (Twitter::Place)

    A place in the world. These can be retrieved from PlacesAndGeo#reverse_geocode.

  • :place_id (String)

    A place in the world. These IDs can be retrieved from PlacesAndGeo#reverse_geocode.

  • :display_coordinates (String)

    Whether or not to put a pin on the exact coordinates a tweet has been sent from.

  • :trim_user (Boolean, String, Integer)

    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.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



216
217
218
219
220
221
# File 'lib/twitter/rest/tweets.rb', line 216

def update_with_media(status, media, options = {})
  hash = options.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_with_object(:post, '/1.1/statuses/update_with_media.json', hash.merge('media[]' => media, 'status' => status), Twitter::Tweet)
end