Mercurial > rsstweet
comparison app/models/tweet.rb @ 48:8983c426e256
Prevent exploding on empty timeline.
author | nanaya <me@myconan.net> |
---|---|
date | Thu, 23 Apr 2015 16:14:35 +0900 |
parents | e5082c4c234d |
children | 1161ad2a4390 |
comparison
equal
deleted
inserted
replaced
47:e5082c4c234d | 48:8983c426e256 |
---|---|
1 class Tweet | 1 class Tweet |
2 def timeline | 2 def timeline |
3 @timeline ||= | 3 @timeline ||= |
4 Rails.cache.fetch({ :timeline => @twitter_id }, :expires_in => 5.minutes) do | 4 Rails.cache.fetch({ :timeline => @twitter_id }, :expires_in => 5.minutes) do |
5 @client.user_timeline(@twitter_id) | 5 @client.user_timeline(@twitter_id) |
6 end | |
7 end | |
8 | |
9 def user | |
10 @user ||= | |
11 if timeline.any? | |
12 timeline.first.user | |
13 else | |
14 Rails.cache.fetch({ :user => @twitter_id }, :expires_in => 5.minutes) do | |
15 @client.user(@twitter_id) | |
16 end | |
6 end | 17 end |
7 end | 18 end |
8 | 19 |
9 def initialize(twitter_id) | 20 def initialize(twitter_id) |
10 @client = Twitter::REST::Client.new do |config| | 21 @client = Twitter::REST::Client.new do |config| |