annotate app/models/tweet.rb @ 45:c087f4831ec7

Rails 4.2.
author edogawaconan <me@myconan.net>
date Sat, 20 Dec 2014 17:51:07 +0900
parents 205c0b5d9f44
children e5082c4c234d
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 CONFIG = {
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
3 :consumer_key => ENV["RT_CONSUMER_KEY"],
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
4 :consumer_secret => ENV["RT_CONSUMER_SECRET"],
23
b82d86b74636 Update variable names.
edogawaconan <me@myconan.net>
parents: 21
diff changeset
5 :access_token => ENV["RT_ACCESS_TOKEN"],
b82d86b74636 Update variable names.
edogawaconan <me@myconan.net>
parents: 21
diff changeset
6 :access_token_secret => ENV["RT_ACCESS_TOKEN_SECRET"]
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
7 }
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
8
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
9 def timeline
28
03f904c070f7 Basic caching support.
edogawaconan <me@myconan.net>
parents: 23
diff changeset
10 @timeline ||=
30
205c0b5d9f44 Whoops, expires_in accidentally as key name.
edogawaconan <me@myconan.net>
parents: 28
diff changeset
11 Rails.cache.fetch({ :timeline => @twitter_id }, :expires_in => 5.minutes) do
28
03f904c070f7 Basic caching support.
edogawaconan <me@myconan.net>
parents: 23
diff changeset
12 @client.user_timeline(@twitter_id)
03f904c070f7 Basic caching support.
edogawaconan <me@myconan.net>
parents: 23
diff changeset
13 end
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
14 end
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
16 def initialize(twitter_id)
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
17 @client = Twitter::REST::Client.new do |config|
21
6e3ff830e94a Realign.
edogawaconan <me@myconan.net>
parents: 15
diff changeset
18 CONFIG.each do |cfg_key, cfg_value|
6e3ff830e94a Realign.
edogawaconan <me@myconan.net>
parents: 15
diff changeset
19 config.public_send("#{cfg_key}=", cfg_value)
6e3ff830e94a Realign.
edogawaconan <me@myconan.net>
parents: 15
diff changeset
20 end
6e3ff830e94a Realign.
edogawaconan <me@myconan.net>
parents: 15
diff changeset
21 end
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
22 @twitter_id = twitter_id
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
23 end
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
24 end