comparison app/controllers/tweets_controller.rb @ 203:af84c9f23263

Fix redirect for twitter user with nil screen name Everything else is still kind of broken but it's kind of beyond help anyway
author nanaya <me@nanaya.pro>
date Mon, 19 Oct 2020 03:42:22 +0900
parents 469df6354341
children 8190fa511e35
comparison
equal deleted inserted replaced
202:d12f671185a8 203:af84c9f23263
7 return redirect if params[:id][/D/].present? 7 return redirect if params[:id][/D/].present?
8 8
9 client = Tweet.new(params[:id].to_i) 9 client = Tweet.new(params[:id].to_i)
10 @user = client.user 10 @user = client.user
11 11
12 return redirect if @user.screen_name != params[:name] 12 return redirect if normalized_screen_name != params[:name]
13 13
14 @tweets = client.timeline 14 @tweets = client.timeline
15 rescue Twitter::Error::NotFound 15 rescue Twitter::Error::NotFound
16 head :not_found 16 head :not_found
17 rescue Twitter::Error::Unauthorized 17 rescue Twitter::Error::Unauthorized
18 head :forbidden 18 head :forbidden
19 end 19 end
20 20
21 def redirect 21 def redirect
22 @user ||= Tweet.new(params[:id].presence || params[:name]).user 22 @user ||= Tweet.new(params[:id].presence || params[:name]).user
23 redirect_to tweet_path(@user.id, @user.screen_name) 23 redirect_to tweet_path(@user.id, normalized_screen_name)
24 rescue Twitter::Error::NotFound 24 rescue Twitter::Error::NotFound
25 head :not_found 25 head :not_found
26 rescue Twitter::Error::Unauthorized 26 rescue Twitter::Error::Unauthorized
27 head :forbidden 27 head :forbidden
28 end 28 end
29
30 private
31 def normalized_screen_name
32 @user.screen_name.presence || '_'
33 end
29 end 34 end