Mercurial > rsstweet
annotate app/controllers/tweets_controller.rb @ 215:1c1f761f2dcc
The parameter is still required in production so it turned out
author | nanaya <me@nanaya.pro> |
---|---|
date | Fri, 11 Dec 2020 03:52:35 +0900 |
parents | f9fd9d9cab97 |
children | 0f0cc55ff11b |
rev | line source |
---|---|
15 | 1 class TweetsController < ApplicationController |
38
9e03bbbb1d43
Move static#index to tweet#index.
edogawaconan <me@myconan.net>
parents:
28
diff
changeset
|
2 def index |
166 | 3 return redirect if params[:id].present? || params[:name].present? |
38
9e03bbbb1d43
Move static#index to tweet#index.
edogawaconan <me@myconan.net>
parents:
28
diff
changeset
|
4 end |
9e03bbbb1d43
Move static#index to tweet#index.
edogawaconan <me@myconan.net>
parents:
28
diff
changeset
|
5 |
15 | 6 def show |
165 | 7 return redirect if params[:id][/D/].present? |
8 | |
9 client = Tweet.new(params[:id].to_i) | |
10 @user = client.user | |
11 | |
203
af84c9f23263
Fix redirect for twitter user with nil screen name
nanaya <me@nanaya.pro>
parents:
166
diff
changeset
|
12 return redirect if normalized_screen_name != params[:name] |
165 | 13 |
86
5bfc986200db
The caching becomes a bit confusing because of parameters
nanaya <me@myconan.net>
parents:
81
diff
changeset
|
14 @tweets = client.timeline |
207 | 15 rescue Twitter::Error::Forbidden |
16 head :forbidden | |
25 | 17 rescue Twitter::Error::NotFound |
18 head :not_found | |
19 rescue Twitter::Error::Unauthorized | |
20 head :forbidden | |
15 | 21 end |
55
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
22 |
165 | 23 def redirect |
166 | 24 @user ||= Tweet.new(params[:id].presence || params[:name]).user |
203
af84c9f23263
Fix redirect for twitter user with nil screen name
nanaya <me@nanaya.pro>
parents:
166
diff
changeset
|
25 redirect_to tweet_path(@user.id, normalized_screen_name) |
207 | 26 rescue Twitter::Error::Forbidden |
27 head :forbidden | |
55
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
28 rescue Twitter::Error::NotFound |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
29 head :not_found |
87
b01b5265e6d1
Whoops, forgot to rescue somewhere else
nanaya <me@myconan.net>
parents:
86
diff
changeset
|
30 rescue Twitter::Error::Unauthorized |
b01b5265e6d1
Whoops, forgot to rescue somewhere else
nanaya <me@myconan.net>
parents:
86
diff
changeset
|
31 head :forbidden |
55
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
32 end |
203
af84c9f23263
Fix redirect for twitter user with nil screen name
nanaya <me@nanaya.pro>
parents:
166
diff
changeset
|
33 |
af84c9f23263
Fix redirect for twitter user with nil screen name
nanaya <me@nanaya.pro>
parents:
166
diff
changeset
|
34 private |
205 | 35 |
203
af84c9f23263
Fix redirect for twitter user with nil screen name
nanaya <me@nanaya.pro>
parents:
166
diff
changeset
|
36 def normalized_screen_name |
af84c9f23263
Fix redirect for twitter user with nil screen name
nanaya <me@nanaya.pro>
parents:
166
diff
changeset
|
37 @user.screen_name.presence || '_' |
af84c9f23263
Fix redirect for twitter user with nil screen name
nanaya <me@nanaya.pro>
parents:
166
diff
changeset
|
38 end |
15 | 39 end |