annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
1 class Tweet
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
2 def timeline
28
03f904c070f7 Basic caching support.
edogawaconan <me@myconan.net>
parents: 23
diff changeset
3 @timeline ||=
30
205c0b5d9f44 Whoops, expires_in accidentally as key name.
edogawaconan <me@myconan.net>
parents: 28
diff changeset
4 Rails.cache.fetch({ :timeline => @twitter_id }, :expires_in => 5.minutes) do
28
03f904c070f7 Basic caching support.
edogawaconan <me@myconan.net>
parents: 23
diff changeset
5 @client.user_timeline(@twitter_id)
03f904c070f7 Basic caching support.
edogawaconan <me@myconan.net>
parents: 23
diff changeset
6 end
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
7 end
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
8
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
9 def initialize(twitter_id)
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
10 @client = Twitter::REST::Client.new do |config|
47
e5082c4c234d Also allow config-file-based configuration.
nanaya <me@myconan.net>
parents: 30
diff changeset
11 CFG[:twitter].each do |cfg_key, cfg_value|
21
6e3ff830e94a Realign.
edogawaconan <me@myconan.net>
parents: 15
diff changeset
12 config.public_send("#{cfg_key}=", cfg_value)
6e3ff830e94a Realign.
edogawaconan <me@myconan.net>
parents: 15
diff changeset
13 end
6e3ff830e94a Realign.
edogawaconan <me@myconan.net>
parents: 15
diff changeset
14 end
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
15 @twitter_id = twitter_id
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
16 end
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
17 end