Class: Twitter::Tweet

Inherits:
Object
  • Object
show all
Includes:
StronglyTyped::Model
Defined in:
lib/twitter/tweet.rb

Overview

Note:

Inspired from twitter-4.5.0/lib/twitter/api/timelines.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build_tweets(ary) ⇒ Array<Tweet>

Transform a json array into a collection of tweets

Examples:

ary = [{'created_at'=>'2013-02-28', 'id'=>3, 'text'=>'hello world'}]
Twitter::Tweet.build_tweets(ary)
#=> [#<Twitter::Tweet:0x07.. @id="3", @text="hello world", @created_at=#<DateTime: 2013-02-27>>]

Parameters:

  • ary (Array<Hash>)

    the json twitter results turned into an array of hashes

Returns:

  • (Array<Tweet>)

    the array of Tweets normalized objects



20
21
22
23
24
25
26
27
28
# File 'lib/twitter/tweet.rb', line 20

def build_tweets(ary)
  tweets = ary.map do |tweet|
    args = { id:          tweet['id'],
             text:        tweet['text'],
             created_at:  tweet['created_at'],
             screen_name: tweet['user']['screen_name'] }
    new(args)
  end
end

Instance Method Details

#status_urlObject



39
40
41
# File 'lib/twitter/tweet.rb', line 39

def status_url
  "https://twitter.com/#{screen_name}/status/#{id}"
end