Mercurial > rsstweet
diff app/models/tweet.rb @ 160:4e4195e60c2b
Add check at user level as well
author | nanaya <me@nanaya.pro> |
---|---|
date | Fri, 03 Aug 2018 01:45:16 +0900 |
parents | 74422bae017d |
children | c2e9d3a36bde |
line wrap: on
line diff
--- a/app/models/tweet.rb Fri Aug 03 01:39:15 2018 +0900 +++ b/app/models/tweet.rb Fri Aug 03 01:45:16 2018 +0900 @@ -27,7 +27,7 @@ if data[:result] == :ok if data[:data].any? && data[:data].first.user.id != id wrong_user = data[:data].first.user - throw "Wrong timeline data. Requested: #{id}, got: #{wrong_user.id} (#{wrong_user.name.printable})" + throw "Wrong timeline data. Requested: #{id}, got: #{wrong_user.id} (#{wrong_user.screen_name.printable})" end data[:data] = data[:data].select do |tweet| @@ -48,7 +48,15 @@ def user if @user.nil? raw = Rails.cache.fetch("user:v1:#{@twitter_id}", :expires_in => self.class.cache_expires_time) do - client_try :user, @twitter_id + client_try(:user, @twitter_id).tap do |data| + if data[:result] == :ok + user = data[:data] + + if user.id != @twitter_id || user.screen_name != @twitter_id + throw "Wrong user data. Requested: #{@twitter_id}, got: #{user.id} (#{user.screen_name.printable})" + end + end + end end raise Twitter::Error::NotFound if raw[:result] == :not_found