view app/models/tweet.rb @ 47:e5082c4c234d

Also allow config-file-based configuration.
author nanaya <me@myconan.net>
date Thu, 23 Apr 2015 16:05:08 +0900
parents 205c0b5d9f44
children 8983c426e256
line wrap: on
line source

class Tweet
  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|
      CFG[:twitter].each do |cfg_key, cfg_value|
        config.public_send("#{cfg_key}=", cfg_value)
      end
    end
    @twitter_id = twitter_id
  end
end