Mercurial > rsstweet
comparison app/controllers/tweets_controller.rb @ 234:7a773720d81f legit-client
Totally legit client
author | nanaya <me@nanaya.net> |
---|---|
date | Fri, 14 Jul 2023 22:42:20 +0900 |
parents | 0f0cc55ff11b |
children | 4222343d9433 |
comparison
equal
deleted
inserted
replaced
233:0f0cc55ff11b | 234:7a773720d81f |
---|---|
1 class TweetsController < ApplicationController | 1 class TweetsController < ApplicationController |
2 def index | 2 def index |
3 return redirect if params[:id].present? || params[:name].present? | 3 return redirect if params[:name].present? |
4 end | 4 end |
5 | 5 |
6 def show | 6 def show |
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 @user = CachedFetch.user_by_id params[:id] |
10 @user = client.user | 10 |
11 if @user.nil? | |
12 head :not_found | |
13 return | |
14 end | |
11 | 15 |
12 return redirect if normalized_screen_name != params[:name] | 16 return redirect if normalized_screen_name != params[:name] |
13 | 17 |
14 @tweets = client.timeline | 18 @tweets = CachedFetch.timeline params[:id] |
15 rescue Twitter::Error::Forbidden | 19 |
16 head :forbidden | 20 head :not_found if @tweets.nil? |
17 rescue Twitter::Error::NotFound | |
18 head :not_found | |
19 rescue Twitter::Error::Unauthorized | |
20 head :forbidden | |
21 end | 21 end |
22 | 22 |
23 def redirect | 23 def redirect |
24 @user ||= Tweet.new(params[:id].presence || params[:name]).user | 24 @user ||= CachedFetch.user_by_username(params[:name]) |
25 redirect_to tweet_path(@user.id, normalized_screen_name) | 25 |
26 rescue Twitter::Error::Forbidden | 26 if @user.nil? |
27 head :forbidden | 27 head :not_found |
28 rescue Twitter::Error::NotFound | 28 else |
29 head :not_found | 29 redirect_to tweet_path(@user[:id], normalized_screen_name) |
30 rescue Twitter::Error::Unauthorized | 30 end |
31 head :forbidden | |
32 end | 31 end |
33 | 32 |
34 private | 33 private |
35 | 34 |
36 def normalized_screen_name | 35 def normalized_screen_name |
37 @user.screen_name.presence || '_' | 36 @user[:username].presence || '_' |
38 end | 37 end |
39 end | 38 end |