Mercurial > rsstweet
annotate app/models/tweet.rb @ 60:122df25a3466
Always enable npm
Current one was wrong since rails doesn't require non-default groups.
author | nanaya <me@myconan.net> |
---|---|
date | Mon, 16 Nov 2015 01:19:26 +0900 |
parents | 8983c426e256 |
children | 1161ad2a4390 |
rev | line source |
---|---|
15 | 1 class Tweet |
2 def timeline | |
28 | 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 | 5 @client.user_timeline(@twitter_id) |
6 end | |
15 | 7 end |
8 | |
48
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
47
diff
changeset
|
9 def user |
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
47
diff
changeset
|
10 @user ||= |
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
47
diff
changeset
|
11 if timeline.any? |
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
47
diff
changeset
|
12 timeline.first.user |
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
47
diff
changeset
|
13 else |
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
47
diff
changeset
|
14 Rails.cache.fetch({ :user => @twitter_id }, :expires_in => 5.minutes) do |
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
47
diff
changeset
|
15 @client.user(@twitter_id) |
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
47
diff
changeset
|
16 end |
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
47
diff
changeset
|
17 end |
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
47
diff
changeset
|
18 end |
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
47
diff
changeset
|
19 |
15 | 20 def initialize(twitter_id) |
21 @client = Twitter::REST::Client.new do |config| | |
47
e5082c4c234d
Also allow config-file-based configuration.
nanaya <me@myconan.net>
parents:
30
diff
changeset
|
22 CFG[:twitter].each do |cfg_key, cfg_value| |
21 | 23 config.public_send("#{cfg_key}=", cfg_value) |
24 end | |
25 end | |
15 | 26 @twitter_id = twitter_id |
27 end | |
28 end |