Skip to content

Commit

Permalink
Revised Tweeter list, sorting by tweet count
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousepic committed Nov 8, 2014
1 parent a88d47c commit e223705
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
25 changes: 21 additions & 4 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,28 @@ def index
config.access_token = twitter_auth.token
config.access_token_secret = twitter_auth.secret
end
@user_list = []
@timeline = client.home_timeline(options = {count: 200})
@timeline.each do |t|
@user_list << { user_id: t.user, user_name: t.user.name , user_screen_name: t.user.screen_name }

timeline_users = []
timeline = client.home_timeline(options = {count: 200})
timeline.each do |t|
timeline_users << { user_id: t.user.id,
user_name: t.user.name,
user_screen_name: t.user.screen_name}
end
user_list = []
timeline_users.each do |t|
user_index = user_list.find_index{ |h| h[:user_id] == t[:user_id] }
if user_index == nil
user_list << { user_id: t[:user_id],
user_name: t[:user_name],
user_screen_name: t[:user_screen_name],
tweet_count: 1}
else
user_list[user_index][:tweet_count] += 1
end

end
@display_list = user_list.sort_by! { |u| u[:tweet_count]}.reverse
end
end
end
Expand Down
5 changes: 1 addition & 4 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@
<%= link_to "Log in via Twitter", "/auth/twitter" %>
<% else %>
<p>Logged in as <%= current_user.name %></p>
<%= @user_list %>
<%#= @user_timeline %>
<%#= HTTParty.get("https://api.twitter.com/1.1/statuses/home_timeline.json",
{ authorization: "token #{twitter_auth.token}" }) %>
<%= @display_list %>
<% end %>

0 comments on commit e223705

Please sign in to comment.