Mercurial > rsstweet
annotate app/controllers/tweets_controller.rb @ 125:61414d0a367b
Less breakage
author | nanaya <me@nanaya.pro> |
---|---|
date | Wed, 23 Aug 2017 16:35:58 +0900 |
parents | 32c8c150cd80 |
children | 3ff631612493 |
rev | line source |
---|---|
15 | 1 class TweetsController < ApplicationController |
55
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
2 before_action :validate_id, :only => :show |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
3 |
38
9e03bbbb1d43
Move static#index to tweet#index.
edogawaconan <me@myconan.net>
parents:
28
diff
changeset
|
4 def index |
116 | 5 return try_redirect if params[:id] |
38
9e03bbbb1d43
Move static#index to tweet#index.
edogawaconan <me@myconan.net>
parents:
28
diff
changeset
|
6 end |
9e03bbbb1d43
Move static#index to tweet#index.
edogawaconan <me@myconan.net>
parents:
28
diff
changeset
|
7 |
15 | 8 def show |
48
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
38
diff
changeset
|
9 client = Tweet.new(params[:id]) |
86
5bfc986200db
The caching becomes a bit confusing because of parameters
nanaya <me@myconan.net>
parents:
81
diff
changeset
|
10 @tweets = client.timeline |
48
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
38
diff
changeset
|
11 @user = client.user |
25 | 12 rescue Twitter::Error::NotFound |
13 head :not_found | |
14 rescue Twitter::Error::Unauthorized | |
15 head :forbidden | |
15 | 16 end |
55
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
17 |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
18 private |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
19 |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
20 def validate_id |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
21 id = params[:id].split("/")[0] |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
22 int_id = id.to_i |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
23 if int_id.to_s == id |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
24 params[:id] = int_id |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
25 else |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
26 try_redirect |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
27 end |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
28 end |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
29 |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
30 def try_redirect |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
31 user = Tweet.new(params[:id]).user |
67
5dd24a65547b
Should be screen name (@-name), not just name.
nanaya <me@myconan.net>
parents:
66
diff
changeset
|
32 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
|
33 rescue Twitter::Error::NotFound |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
34 head :not_found |
87
b01b5265e6d1
Whoops, forgot to rescue somewhere else
nanaya <me@myconan.net>
parents:
86
diff
changeset
|
35 rescue Twitter::Error::Unauthorized |
b01b5265e6d1
Whoops, forgot to rescue somewhere else
nanaya <me@myconan.net>
parents:
86
diff
changeset
|
36 head :forbidden |
55
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
37 end |
15 | 38 end |