Browse files

Added home timeline

  • Loading branch information...
1 parent 727f1db commit 5c17bb09ff97e4760ee794c79869383211460c32 @yayugu committed Mar 3, 2014
Showing with 25 additions and 2 deletions.
  1. +8 −0 app/controllers/feed_controller.rb
  2. +4 −0 app/views/feed/home.erb
  3. +4 −2 app/views/main/index.html.slim
  4. +1 −0 config/routes.rb
  5. +8 −0 lib/twitter_client.rb
View
8 app/controllers/feed_controller.rb
@@ -3,6 +3,14 @@ class FeedController < ApplicationController
before_action :prepare_twitter_client
+ def home
+ res = @client.home(TWEET_COUNT)
+ render_error and return if res.error
+
+ @tweets = Tweet.tweets_from_hash_list(res.body)
+ render_rss
+ end
+
def user
res = @client.user(params[:name], TWEET_COUNT)
render_error and return if res.error
View
4 app/views/feed/home.erb
@@ -0,0 +1,4 @@
+<%
+@title = "Home Timeline / Twitter"
+@link = "http://twitter.com/"
+%><%= render partial: "rss" %>
View
6 app/views/main/index.html.slim
@@ -4,6 +4,7 @@ div
- if @user
div You can generate RSS with URL like:
ul
+ li #{root_url}feed/home?url_id_hash=#{@user.url_id_hash}
li #{root_url}feed/user?user=USERNAME&url_id_hash=#{@user.url_id_hash}
li #{root_url}feed/list?user=USERNAME&slug=LISTNAME&url_id_hash=#{@user.url_id_hash}
li #{root_url}feed/search?q=KEYWORD&url_id_hash=#{@user.url_id_hash}
@@ -16,13 +17,14 @@ div
== link_to "Logout", controller: "auth", action: "logout"
- else
- div
- == link_to "Sign in with twitter", controller: "auth", action: "auth"
div Generate RSS for:
ul
+ li timeline tweets
li user tweets
li list tweets
li search result tweets
+ div
+ == link_to "Sign in with twitter", controller: "auth", action: "auth"
br
div
View
1 config/routes.rb
@@ -8,6 +8,7 @@
end
scope :feed do
+ get 'home' => 'feed#home'
get 'user' => 'feed#user'
get 'list' => 'feed#list'
get 'search' => 'feed#search'
View
8 lib/twitter_client.rb
@@ -7,6 +7,10 @@ def initialize(access_token, access_secret)
@access_token = OAuth::AccessToken.new(OAuthTwitter.new.consumer, access_token, access_secret)
end
+ def home(count)
+ get_and_json_parse(home_sub_url(count))
+ end
+
def user(name, count)
get_and_json_parse(user_sub_url(name, count))
end
@@ -23,6 +27,10 @@ def search(query, count)
private
+ def home_sub_url(count)
+ "/statuses/home_timeline.json?include_entities=true&count=#{count}&include_rts=true"
+ end
+
def user_sub_url(name, count)
"/statuses/user_timeline.json?screen_name=#{name}&include_entities=true&count=#{count}&include_rts=true"
end

0 comments on commit 5c17bb0

Please sign in to comment.