Mercurial > rsstweet
comparison 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 |
comparison
equal
deleted
inserted
replaced
46:92b22027d0ae | 47:e5082c4c234d |
---|---|
1 class Tweet | 1 class Tweet |
2 CONFIG = { | |
3 :consumer_key => ENV["RT_CONSUMER_KEY"], | |
4 :consumer_secret => ENV["RT_CONSUMER_SECRET"], | |
5 :access_token => ENV["RT_ACCESS_TOKEN"], | |
6 :access_token_secret => ENV["RT_ACCESS_TOKEN_SECRET"] | |
7 } | |
8 | |
9 def timeline | 2 def timeline |
10 @timeline ||= | 3 @timeline ||= |
11 Rails.cache.fetch({ :timeline => @twitter_id }, :expires_in => 5.minutes) do | 4 Rails.cache.fetch({ :timeline => @twitter_id }, :expires_in => 5.minutes) do |
12 @client.user_timeline(@twitter_id) | 5 @client.user_timeline(@twitter_id) |
13 end | 6 end |
14 end | 7 end |
15 | 8 |
16 def initialize(twitter_id) | 9 def initialize(twitter_id) |
17 @client = Twitter::REST::Client.new do |config| | 10 @client = Twitter::REST::Client.new do |config| |
18 CONFIG.each do |cfg_key, cfg_value| | 11 CFG[:twitter].each do |cfg_key, cfg_value| |
19 config.public_send("#{cfg_key}=", cfg_value) | 12 config.public_send("#{cfg_key}=", cfg_value) |
20 end | 13 end |
21 end | 14 end |
22 @twitter_id = twitter_id | 15 @twitter_id = twitter_id |
23 end | 16 end |