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
# File 'lib/statement/tweets.rb', line 8

def initialize
  @@config = YAML.load_file("config.yml") rescue nil || {}
  @client = Twitter::Client.new(
      :consumer_key => ENV['CONSUMER_KEY'] || @@config['consumer_key'],
      :consumer_secret => ENV['CONSUMER_SECRET'] || @@config['consumer_secret'],
      :oauth_token => ENV['OAUTH_TOKEN'] || @@config['oauth_token'],
      :oauth_token_secret => ENV['OAUTH_TOKEN_SECRET'] || @@config['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)



33
34
35
# File 'lib/statement/tweets.rb', line 33

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

#timeline(member_id) ⇒ Object

fetches single twitter user’s timeline



19
20
21
# File 'lib/statement/tweets.rb', line 19

def timeline
  @timeline
end

Instance Method Details

#process_results(tweets) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/statement/tweets.rb', line 37

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



24
25
26
27
28
29
30
# File 'lib/statement/tweets.rb', line 24

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