class Statement::Tweets

Attributes

bulk_timeline[RW]
client[RW]
rest_client[RW]
timeline[RW]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

process_results(tweets) click to toggle source
# 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) click to toggle source

batch lookup of users, 100 at a time

# 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