Class: Twitter::Tweet

Inherits:
Identity show all
Includes:
Creatable, Entities
Defined in:
lib/twitter/tweet.rb

Overview

Represents a Twitter tweet

Instance Attribute Summary collapse

Attributes inherited from Identity

#id

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods included from Entities

#entities?, #hashtags, #hashtags?, #media, #media?, #symbols, #symbols?, #uris, #uris?, #user_mentions, #user_mentions?

Methods included from Creatable

#created?, #created_at

Methods inherited from Base

#[], attr_reader, define_attribute_method, define_predicate_method, define_uri_method, display_uri_attr_reader, object_attr_reader, predicate_attr_reader, uri_attr_reader

Methods included from Utils

flat_pmap, pmap

Constructor Details

#initialize(attrs) ⇒ Twitter::Tweet

Initializes a new Tweet object

Examples:

Twitter::Tweet.new(id: 123, text: "Hello")

Parameters:

  • attrs (Hash)

    The attributes hash containing at least :id



178
179
180
181
# File 'lib/twitter/tweet.rb', line 178

def initialize(attrs)
  attrs[:text] ||= attrs[:full_text]
  super
end

Instance Attribute Details

#favorite_countInteger (readonly)

The number of times this tweet has been retweeted

Examples:

tweet.retweet_count

Returns:

  • (Integer)


88
89
90
# File 'lib/twitter/tweet.rb', line 88

def favorite_count
  @favorite_count
end

#filter_levelString (readonly)

The text of the tweet

Examples:

tweet.text

Returns:

  • (String)


45
46
47
# File 'lib/twitter/tweet.rb', line 45

def filter_level
  @filter_level
end

#in_reply_to_screen_nameString (readonly)

The text of the tweet

Examples:

tweet.text

Returns:

  • (String)


45
46
47
# File 'lib/twitter/tweet.rb', line 45

def in_reply_to_screen_name
  @in_reply_to_screen_name
end

#in_reply_to_status_idInteger (readonly) Also known as: in_reply_to_tweet_id

The number of times this tweet has been retweeted

Examples:

tweet.retweet_count

Returns:

  • (Integer)


88
89
90
# File 'lib/twitter/tweet.rb', line 88

def in_reply_to_status_id
  @in_reply_to_status_id
end

#in_reply_to_user_idInteger (readonly)

The number of times this tweet has been retweeted

Examples:

tweet.retweet_count

Returns:

  • (Integer)


88
89
90
# File 'lib/twitter/tweet.rb', line 88

def in_reply_to_user_id
  @in_reply_to_user_id
end

#langString (readonly)

The text of the tweet

Examples:

tweet.text

Returns:

  • (String)


45
46
47
# File 'lib/twitter/tweet.rb', line 45

def lang
  @lang
end

#quote_countInteger (readonly)

The number of times this tweet has been retweeted

Examples:

tweet.retweet_count

Returns:

  • (Integer)


88
89
90
# File 'lib/twitter/tweet.rb', line 88

def quote_count
  @quote_count
end

#reply_countInteger (readonly)

The number of times this tweet has been retweeted

Examples:

tweet.retweet_count

Returns:

  • (Integer)


88
89
90
# File 'lib/twitter/tweet.rb', line 88

def reply_count
  @reply_count
end

#retweet_countInteger (readonly)

The number of times this tweet has been retweeted

Examples:

tweet.retweet_count

Returns:

  • (Integer)


88
89
90
# File 'lib/twitter/tweet.rb', line 88

def retweet_count
  @retweet_count
end

#sourceString (readonly)

The text of the tweet

Examples:

tweet.text

Returns:

  • (String)


45
46
47
# File 'lib/twitter/tweet.rb', line 45

def source
  @source
end

#textString (readonly)

The text of the tweet

Examples:

tweet.text

Returns:

  • (String)


45
46
47
# File 'lib/twitter/tweet.rb', line 45

def text
  @text
end

Instance Method Details

#full_textString

Note:

May be > 280 characters

Returns the full text of the tweet

Examples:

tweet.full_text

Returns:

  • (String)


190
191
192
193
194
195
196
197
# File 'lib/twitter/tweet.rb', line 190

def full_text
  if retweet?
    prefix = text[/\A(RT @[a-z0-9_]{1,20}: )/i, 1]
    [prefix, retweeted_status.text].compact.join
  else
    text
  end
end

#uriURI::Generic Also known as: url

Returns the URI to the tweet

Examples:

tweet.uri

Returns:

  • (URI::Generic)


206
207
208
# File 'lib/twitter/tweet.rb', line 206

def uri
  URI.parse("https://twitter.com/#{user.screen_name}/status/#{id}") if user?
end