Class: Statement::Tweets

Inherits:
Object
  • Object
show all
Defined in:
lib/statement/tweets.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTweets

Returns a new instance of Tweets.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/statement/tweets.rb', line 8

def initialize
  @@config = Statement.config rescue nil || {}
  @client = Twitter::Client.new(
      :consumer_key => @@config[:consumer_key] || ENV['CONSUMER_KEY'],
      :consumer_secret => @@config[:consumer_secret] || ENV['CONSUMER_SECRET'],
      :oauth_token => @@config[:oauth_token] || ENV['OAUTH_TOKEN'],
      :oauth_token_secret => @@config[:oauth_token_secret] || ENV['OAUTH_TOKEN_SECRET']
    )
  @rest_client = Twitter::REST::Client.new(
      :consumer_key => @@config[:consumer_key] || ENV['CONSUMER_KEY'],
      :consumer_secret => @@config[:consumer_secret] || ENV['CONSUMER_SECRET'],
      :oauth_token => @@config[:oauth_token] || ENV['OAUTH_TOKEN'],
      :oauth_token_secret => @@config[:oauth_token_secret] || ENV['OAUTH_TOKEN_SECRET']
    )
end

Instance Attribute Details

#bulk_timeline(list_id, list_owner = nil) ⇒ Object

fetches latest 100 tweets from a list (derekwillis twitter acct has a public congress list)



39
40
41
# File 'lib/statement/tweets.rb', line 39

def bulk_timeline
  @bulk_timeline
end

#clientObject

Returns the value of attribute client.



6
7
8
# File 'lib/statement/tweets.rb', line 6

def client
  @client
end

#rest_clientObject

Returns the value of attribute rest_client.



6
7
8
# File 'lib/statement/tweets.rb', line 6

def rest_client
  @rest_client
end

#timeline(member_id) ⇒ Object

fetches single twitter user’s timeline



25
26
27
# File 'lib/statement/tweets.rb', line 25

def timeline
  @timeline
end

Instance Method Details

#process_results(tweets) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/statement/tweets.rb', line 43

def process_results(tweets)
  results = []
  tweets.each do |tweet|
    url = tweet.urls.first ? tweet.urls.first.expanded_url : nil
    results << { :id => tweet.id, :body => tweet.text, :link => url, :in_reply_to_screen_name => tweet.in_reply_to_screen_name, :total_tweets => tweet.user.statuses_count, :created_time => tweet.created_at, :retweets => tweet.retweet_count, :favorites => tweet.favorite_count, :screen_name => tweet.user.screen_name}
  end
  results
end

#users(member_ids) ⇒ Object

batch lookup of users, 100 at a time



30
31
32
33
34
35
36
# File 'lib/statement/tweets.rb', line 30

def users(member_ids)
  results = []
  member_ids.each_slice(100) do |batch|
    results << rest_client.users(batch)
  end
  results.flatten
end