Mercurial > rsstweet
comparison app/controllers/tweets_controller.rb @ 245:2935c5e52a71
No more official twitter api
author | nanaya <me@nanaya.net> |
---|---|
date | Mon, 17 Jul 2023 04:23:09 +0900 |
parents | 4222343d9433 |
children | e2150dce4e90 |
comparison
equal
deleted
inserted
replaced
233:0f0cc55ff11b | 245:2935c5e52a71 |
---|---|
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 | |
15 | |
16 if @user[:protected] | |
17 head :forbidden | |
18 return | |
19 end | |
11 | 20 |
12 return redirect if normalized_screen_name != params[:name] | 21 return redirect if normalized_screen_name != params[:name] |
13 | 22 |
14 @tweets = client.timeline | 23 @tweets = CachedFetch.timeline params[:id] |
15 rescue Twitter::Error::Forbidden | 24 |
16 head :forbidden | 25 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 | 26 end |
22 | 27 |
23 def redirect | 28 def redirect |
24 @user ||= Tweet.new(params[:id].presence || params[:name]).user | 29 @user ||= CachedFetch.user_by_username(params[:name]) |
25 redirect_to tweet_path(@user.id, normalized_screen_name) | 30 |
26 rescue Twitter::Error::Forbidden | 31 if @user.nil? |
27 head :forbidden | 32 head :not_found |
28 rescue Twitter::Error::NotFound | 33 else |
29 head :not_found | 34 redirect_to tweet_path(@user[:id], normalized_screen_name) |
30 rescue Twitter::Error::Unauthorized | 35 end |
31 head :forbidden | |
32 end | 36 end |
33 | 37 |
34 private | 38 private |
35 | 39 |
36 def normalized_screen_name | 40 def normalized_screen_name |
37 @user.screen_name.presence || '_' | 41 @user[:username].presence || '_' |
38 end | 42 end |
39 end | 43 end |