aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb13
-rw-r--r--app/controllers/errors_controller.rb15
-rw-r--r--app/controllers/i_controller.rb21
-rw-r--r--app/controllers/users_controller.rb45
-rw-r--r--app/models/tweet.rb10
-rw-r--r--app/views/i/show.html.haml (renamed from app/views/users/show.html.haml)0
-rw-r--r--app/views/i/show.json.jbuilder2
-rw-r--r--app/views/main/index.html.haml30
-rw-r--r--app/views/shared/_tweet.html.haml2
-rw-r--r--app/views/shared/_tweet.json.jbuilder24
-rw-r--r--app/views/shared/_user_nav.html.haml2
-rw-r--r--app/views/users/discovered.html.haml (renamed from app/views/users/my.html.haml)0
-rw-r--r--app/views/users/discovered.json.jbuilder (renamed from app/views/users/my.json.jbuilder)0
-rw-r--r--app/views/users/show.json.jbuilder2
14 files changed, 116 insertions, 50 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 93eb126..b6320a7 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -9,11 +9,22 @@ class ApplicationController < ActionController::Base
end
def get_page_number(params)
- if params[:page] && i = params[:page].to_i
+ if params[:page]
+ i = params[:page].to_i
if i > 0
return i
end
end
return 1
end
+
+ def get_page_count(params)
+ if params[:count]
+ i = params[:count].to_i
+ if i && i > 0 && i <= 100
+ return i
+ end
+ end
+ return Settings.page_per
+ end
end
diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb
index 170f2aa..1fa42cb 100644
--- a/app/controllers/errors_controller.rb
+++ b/app/controllers/errors_controller.rb
@@ -1,7 +1,16 @@
class ErrorsController < ApplicationController
- def error_404
- end
+ def render_error
+ @exception = env["action_dispatch.exception"]
+ @status = ActionDispatch::ExceptionWrapper.new(env, @exception).status_code
+
+ respond_to do |format|
+ format.html do
+ render "error_#{@status}", :status => @status
+ end
- def error_500
+ format.json do
+ render "error_#{@status}", :status => @status
+ end
+ end
end
end
diff --git a/app/controllers/i_controller.rb b/app/controllers/i_controller.rb
index 7ee38da..90e1d01 100644
--- a/app/controllers/i_controller.rb
+++ b/app/controllers/i_controller.rb
@@ -3,7 +3,7 @@ class IController < ApplicationController
@items = Tweet
.reacted
.order_by_reactions
- .limit(Settings.page_per)
+ .limit(get_page_count(params))
end
def recent
@@ -11,6 +11,23 @@ class IController < ApplicationController
.recent
.reacted
.order_by_reactions
- .limit(Settings.page_per)
+ .limit(get_page_count(params))
+ end
+
+ def show
+ tweet_id = Integer(params[:id])
+
+ @item = Tweet.find(tweet_id)
+ @user = @item.user
+ helpers = ApplicationController.helpers
+ @title = "\"#{helpers.strip_tags(helpers.format_tweet_text(@item.text))[0...30]}\" from @#{@item.user.screen_name}"
+
+ respond_to do |format|
+ format.html
+
+ format.json do
+ @trim_user = params[:trim_user] == "true"
+ end
+ end
end
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 1ebb5a6..cc11c2e 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,23 +1,4 @@
class UsersController < ApplicationController
- def show
- tweet_id = Integer(params[:id])
-
- @item = Tweet.find(tweet_id)
- @user = @item.user
- helpers = ApplicationController.helpers
- @title = "\"#{helpers.strip_tags(helpers.format_tweet_text(@item.text))[0...30]}\" from @#{@item.user.screen_name}"
-
- respond_to do |format|
- format.html do
- prepare_info
- end
-
- format.json do
- @trim_user = params[:trim_user] == "true"
- end
- end
- end
-
def best
user = render_timeline(params) do |tweets, user|
tweets.of(user).reacted.order_by_reactions
@@ -47,9 +28,16 @@ class UsersController < ApplicationController
end
end
- def my
+ def discovered
user = render_timeline(params) do |tweets, user|
- tweets.discovered(user).order_by_id
+ case params[:tweets]
+ when "favorite"
+ tweets.favorited_by(user).order_by_id
+ when "retweet"
+ tweets.retweeted_by(user).order_by_id
+ else
+ tweets.discovered_by(user).order_by_id
+ end
end
@title = "@#{user.screen_name}'s Recent Discoveries"
end
@@ -57,24 +45,27 @@ class UsersController < ApplicationController
private
def render_timeline(params, &g)
page = get_page_number(params)
+ count = get_page_count(params)
screen_name = params[:screen_name]
+ user_id = params[:user_id]
@user = User.where(:screen_name => screen_name).first
unless @user
- raise ActiveRecord::RecordNotFound.new(screen_name)
+ @user = User.where(:id => user_id).first
+ unless @user
+ raise ActiveRecord::RecordNotFound.new("screen_name=#{screen_name}&user_id=#{user_id}")
+ end
end
@items = g.call(Tweet, @user)
.page(page)
- .per(Settings.page_per)
+ .per(count)
respond_to do |format|
- format.html do
- prepare_info
- end
+ format.html
format.json do
- @trim_user = params[:trim_user] == "true"
+ @include_user = params[:include_user] == "true"
end
end
diff --git a/app/models/tweet.rb b/app/models/tweet.rb
index 6b6311d..d20377b 100644
--- a/app/models/tweet.rb
+++ b/app/models/tweet.rb
@@ -19,7 +19,15 @@ class Tweet < ActiveRecord::Base
order("COALESCE(favorites_count, 0) + COALESCE(retweets_count, 0) DESC")
end
- scope :discovered, -> user do
+ scope :favorited_by, -> user do
+ where("id IN (SELECT tweet_id FROM favorites WHERE user_id = ?)", user.id)
+ end
+
+ scope :retweeted_by, -> user do
+ where("id IN (SELECT tweet_id FROM retweets WHERE user_id = ?)", user.id)
+ end
+
+ scope :discovered_by, -> user do
where("id IN (" +
"SELECT tweet_id FROM favorites WHERE user_id = ?" +
" UNION ALL " +
diff --git a/app/views/users/show.html.haml b/app/views/i/show.html.haml
index f56e0c0..f56e0c0 100644
--- a/app/views/users/show.html.haml
+++ b/app/views/i/show.html.haml
diff --git a/app/views/i/show.json.jbuilder b/app/views/i/show.json.jbuilder
new file mode 100644
index 0000000..bca1b00
--- /dev/null
+++ b/app/views/i/show.json.jbuilder
@@ -0,0 +1,2 @@
+json.partial! "shared/tweet", :item => @item
+
diff --git a/app/views/main/index.html.haml b/app/views/main/index.html.haml
index dfebde1..6580d77 100644
--- a/app/views/main/index.html.haml
+++ b/app/views/main/index.html.haml
@@ -7,8 +7,6 @@
%p
%strong まだ開発途中段階のものです。うごかなかったらごめんね
%p
- Read/Write 要求するけど今のところ UserStreams しか使ってないです。こんど Favstar みたいにページ内から Fav/RT できるようにしたいなあと…
-%p
%strong 動作のテスト中ですので、途中で登録をうちきったりあまりにふぁぼられ・ふぁぼりが多いユーザーの登録を削除する可能性もあります。
%p
登録ユーザーだったら一番下に統計(?)が表示されてるんじゃないですかね
@@ -21,11 +19,14 @@
recent(最新3日のbest):
= link_to "/cat/recent", "/cat/recent"
%div
- timeline(Favstar の Recent、ただ0Fav0RTも含む):
+ timeline(Favstar の Recent):
= link_to "/cat/timeline", "/cat/timeline"
%div
+ timeline(ユーザータイムライン):
+ = link_to "/cat/timeline/all", "/cat/timeline/all"
+ %div
discovery:
- = link_to "/cat/my", "/cat/my"
+ = link_to "/cat/discovered(/{favorite|retweet})", "/cat/discovered"
%div
%div
全体のbest:
@@ -36,7 +37,26 @@
%div
URL 変えちゃうかもしれないです
%div
- API つくりたいですねハイ
+ API っていえるのかな…?
+ %div
+ %p
+ \/i/show.json?id=[tweet_id]
+ %p
+ \/users/{best|recent|timeline|discovered}.json
+ %p
+ screen_name
+ %p
+ user_id
+ %p
+ count
+ %p
+ include_user=true|false ← fav/RTしたユーザーを取得するか(false で ID のみ
+ %p
+ tweets={*tweet*|all} ← /users/timeline
+ %p
+ tweets={favorite|retweet|*all*} ← discovered
+ %p
+ page
%div
= link_to "@cat", "https://twitter.com/cat"
diff --git a/app/views/shared/_tweet.html.haml b/app/views/shared/_tweet.html.haml
index e706079..4d40f69 100644
--- a/app/views/shared/_tweet.html.haml
+++ b/app/views/shared/_tweet.html.haml
@@ -15,7 +15,7 @@
%span.twitter_bird
= link_to image_tag("bird_gray_16.png", :alt => "Twitter"), twitter_status_url(item), :target => "_blank"
%span.created_at
- = link_to format_tweet_created_at(item.tweeted_at), :controller => "users", :action => "show", :id => item.id
+ = link_to format_tweet_created_at(item.tweeted_at), :controller => "i", :action => "show", :id => item.id
%span.source
= raw format_source_text(item.source)
.stats
diff --git a/app/views/shared/_tweet.json.jbuilder b/app/views/shared/_tweet.json.jbuilder
index a6c22ae..467249a 100644
--- a/app/views/shared/_tweet.json.jbuilder
+++ b/app/views/shared/_tweet.json.jbuilder
@@ -1,18 +1,28 @@
json.(item, :id, :text, :source, :tweeted_at, :favorites_count, :retweets_count)
json.user do |json|
- json.partial! "shared/user", :user => item.user
+ unless @include_user
+ json.id item.user_id
+ else
+ json.partial! "shared/user", :user => item.user
+ end
end
-unless @trim_user
- json.favorites item.favorites.order("id") do |json, favorite|
- json.user do |json|
+json.favorites item.favorites.order("id") do |json, favorite|
+ json.user do |json|
+ unless @include_user
+ json.id favorite.user_id
+ else
json.partial! "shared/user", :user => favorite.user || User.new
end
end
- json.retweets item.retweets.order("id") do |json, retweet|
- json.id retweet.id
- json.user do |json|
+end
+json.retweets item.retweets.order("id") do |json, retweet|
+ json.id retweet.id
+ json.user do |json|
+ unless @include_user
+ json.id retweet.user_id
+ else
json.partial! "shared/user", :user => retweet.user || User.new
end
end
diff --git a/app/views/shared/_user_nav.html.haml b/app/views/shared/_user_nav.html.haml
index 93c7d35..f7a3c7b 100644
--- a/app/views/shared/_user_nav.html.haml
+++ b/app/views/shared/_user_nav.html.haml
@@ -8,4 +8,4 @@
%li
= link_to "Timeline", :controller => "users", :action => "timeline", :screen_name => user.screen_name
%li
- = link_to "Discovered", :controller => "users", :action => "my", :screen_name => user.screen_name
+ = link_to "Discovered", :controller => "users", :action => "discovered", :screen_name => user.screen_name
diff --git a/app/views/users/my.html.haml b/app/views/users/discovered.html.haml
index 1410df9..1410df9 100644
--- a/app/views/users/my.html.haml
+++ b/app/views/users/discovered.html.haml
diff --git a/app/views/users/my.json.jbuilder b/app/views/users/discovered.json.jbuilder
index d2637d3..d2637d3 100644
--- a/app/views/users/my.json.jbuilder
+++ b/app/views/users/discovered.json.jbuilder
diff --git a/app/views/users/show.json.jbuilder b/app/views/users/show.json.jbuilder
deleted file mode 100644
index 049306e..0000000
--- a/app/views/users/show.json.jbuilder
+++ /dev/null
@@ -1,2 +0,0 @@
-json.partial! "shared/tweet", :item => @items.first
-