Mercurial > rsstweet
annotate app/controllers/tweets_controller.rb @ 66:1161ad2a4390
Take care of rt removal from gem api
Double the default count since filtering is done at gem level, not api.
author | nanaya <me@myconan.net> |
---|---|
date | Tue, 01 Dec 2015 01:34:12 +0900 |
parents | 8f68ca606099 |
children | 5dd24a65547b |
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 |
9e03bbbb1d43
Move static#index to tweet#index.
edogawaconan <me@myconan.net>
parents:
28
diff
changeset
|
5 end |
9e03bbbb1d43
Move static#index to tweet#index.
edogawaconan <me@myconan.net>
parents:
28
diff
changeset
|
6 |
15 | 7 def show |
48
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
38
diff
changeset
|
8 client = Tweet.new(params[:id]) |
66
1161ad2a4390
Take care of rt removal from gem api
nanaya <me@myconan.net>
parents:
55
diff
changeset
|
9 @tweets = client.timeline :exclude_replies => true, :count => 40 |
48
8983c426e256
Prevent exploding on empty timeline.
nanaya <me@myconan.net>
parents:
38
diff
changeset
|
10 @user = client.user |
25 | 11 rescue Twitter::Error::NotFound |
12 head :not_found | |
13 rescue Twitter::Error::Unauthorized | |
14 head :forbidden | |
15 | 15 end |
55
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
16 |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
17 private |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
18 |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
19 def validate_id |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
20 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
|
21 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
|
22 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
|
23 params[:id] = int_id |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
24 else |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
25 try_redirect |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
26 end |
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 |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
29 def try_redirect |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
30 user = Tweet.new(params[:id]).user |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
31 redirect_to tweet_path("#{user.id}/#{user.name}") |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
32 rescue Twitter::Error::NotFound |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
33 head :not_found |
8f68ca606099
Add twitter id to the url so it'll be consistent.
nanaya <me@myconan.net>
parents:
48
diff
changeset
|
34 end |
15 | 35 end |