view app/models/tweet.rb @ 38:9e03bbbb1d43

Move static#index to tweet#index.
author edogawaconan <me@myconan.net>
date Thu, 11 Dec 2014 15:47:36 +0900
parents 205c0b5d9f44
children e5082c4c234d
line wrap: on
line source

class Tweet
  CONFIG = {
    :consumer_key => ENV["RT_CONSUMER_KEY"],
    :consumer_secret => ENV["RT_CONSUMER_SECRET"],
    :access_token => ENV["RT_ACCESS_TOKEN"],
    :access_token_secret => ENV["RT_ACCESS_TOKEN_SECRET"]
  }

  def timeline
    @timeline ||=
      Rails.cache.fetch({ :timeline => @twitter_id }, :expires_in => 5.minutes) do
        @client.user_timeline(@twitter_id)
      end
  end

  def initialize(twitter_id)
    @client = Twitter::REST::Client.new do |config|
      CONFIG.each do |cfg_key, cfg_value|
        config.public_send("#{cfg_key}=", cfg_value)
      end
    end
    @twitter_id = twitter_id
  end
end