Mercurial > rsstweet
comparison app/models/tweet.rb @ 165:5af9b537db86
Unbreak \everything/
- simplify routing, no more split hackery
- fix user lookup and differentiate between id and name lookup
author | nanaya <me@nanaya.pro> |
---|---|
date | Fri, 03 Aug 2018 02:31:25 +0900 |
parents | ed73d92c7113 |
children | 08cc4a4d8a5f |
comparison
equal
deleted
inserted
replaced
164:59a4645fd24c | 165:5af9b537db86 |
---|---|
10 (15 + rand(15)).minutes | 10 (15 + rand(15)).minutes |
11 end | 11 end |
12 | 12 |
13 def initialize(twitter_id) | 13 def initialize(twitter_id) |
14 @clients = {} | 14 @clients = {} |
15 @twitter_id = twitter_id.to_s | 15 @twitter_id = twitter_id |
16 end | 16 end |
17 | 17 |
18 def id | 18 def id |
19 user.id | 19 user.id |
20 end | 20 end |
45 @timeline | 45 @timeline |
46 end | 46 end |
47 | 47 |
48 def user | 48 def user |
49 if @user.nil? | 49 if @user.nil? |
50 raw = Rails.cache.fetch("user:v1:#{@twitter_id}", :expires_in => self.class.cache_expires_time) do | 50 cache_key = "user:v1:#{@twitter_id.is_a?(Integer) ? 'id' : 'lookup'}:#{@twitter_id}" |
51 raw = Rails.cache.fetch(cache_key, :expires_in => self.class.cache_expires_time) do | |
51 client_try(:user, @twitter_id).tap do |data| | 52 client_try(:user, @twitter_id).tap do |data| |
52 if data[:result] == :ok | 53 if data[:result] == :ok |
53 user = data[:data] | 54 user = data[:data] |
54 | 55 |
55 if user.id.to_s != @twitter_id && user.screen_name != @twitter_id | 56 if user.id != @twitter_id && user.screen_name.downcase != @twitter_id |
56 throw "Wrong user data. Requested: #{@twitter_id}, got: #{user.id} (#{user.screen_name.printable})" | 57 throw "Wrong user data. Requested: #{@twitter_id}, got: #{user.id} (#{user.screen_name.printable})" |
57 end | 58 end |
58 end | 59 end |
59 end | 60 end |
60 end | 61 end |