annotate app/controllers/tweets_controller.rb @ 195:61d4e974eb50

Use bundler 2
author nanaya <me@nanaya.pro>
date Sun, 23 Feb 2020 18:58:05 +0900
parents 469df6354341
children af84c9f23263
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
1 class TweetsController < ApplicationController
38
9e03bbbb1d43 Move static#index to tweet#index.
edogawaconan <me@myconan.net>
parents: 28
diff changeset
2 def index
166
469df6354341 A more robust check
nanaya <me@nanaya.pro>
parents: 165
diff changeset
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
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
6 def show
165
5af9b537db86 Unbreak \everything/
nanaya <me@nanaya.pro>
parents: 164
diff changeset
7 return redirect if params[:id][/D/].present?
5af9b537db86 Unbreak \everything/
nanaya <me@nanaya.pro>
parents: 164
diff changeset
8
5af9b537db86 Unbreak \everything/
nanaya <me@nanaya.pro>
parents: 164
diff changeset
9 client = Tweet.new(params[:id].to_i)
5af9b537db86 Unbreak \everything/
nanaya <me@nanaya.pro>
parents: 164
diff changeset
10 @user = client.user
5af9b537db86 Unbreak \everything/
nanaya <me@nanaya.pro>
parents: 164
diff changeset
11
5af9b537db86 Unbreak \everything/
nanaya <me@nanaya.pro>
parents: 164
diff changeset
12 return redirect if @user.screen_name != params[:name]
5af9b537db86 Unbreak \everything/
nanaya <me@nanaya.pro>
parents: 164
diff changeset
13
86
5bfc986200db The caching becomes a bit confusing because of parameters
nanaya <me@myconan.net>
parents: 81
diff changeset
14 @tweets = client.timeline
25
70d70736faee Properly rescue 403 and 404.
edogawaconan <me@myconan.net>
parents: 15
diff changeset
15 rescue Twitter::Error::NotFound
70d70736faee Properly rescue 403 and 404.
edogawaconan <me@myconan.net>
parents: 15
diff changeset
16 head :not_found
70d70736faee Properly rescue 403 and 404.
edogawaconan <me@myconan.net>
parents: 15
diff changeset
17 rescue Twitter::Error::Unauthorized
70d70736faee Properly rescue 403 and 404.
edogawaconan <me@myconan.net>
parents: 15
diff changeset
18 head :forbidden
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
19 end
55
8f68ca606099 Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents: 48
diff changeset
20
165
5af9b537db86 Unbreak \everything/
nanaya <me@nanaya.pro>
parents: 164
diff changeset
21 def redirect
166
469df6354341 A more robust check
nanaya <me@nanaya.pro>
parents: 165
diff changeset
22 @user ||= Tweet.new(params[:id].presence || params[:name]).user
165
5af9b537db86 Unbreak \everything/
nanaya <me@nanaya.pro>
parents: 164
diff changeset
23 redirect_to tweet_path(@user.id, @user.screen_name)
55
8f68ca606099 Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents: 48
diff changeset
24 rescue Twitter::Error::NotFound
8f68ca606099 Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents: 48
diff changeset
25 head :not_found
87
b01b5265e6d1 Whoops, forgot to rescue somewhere else
nanaya <me@myconan.net>
parents: 86
diff changeset
26 rescue Twitter::Error::Unauthorized
b01b5265e6d1 Whoops, forgot to rescue somewhere else
nanaya <me@myconan.net>
parents: 86
diff changeset
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 end
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents:
diff changeset
29 end