Permalink
Browse files

added hashtag for user functionality

  • Loading branch information...
1 parent 34cfb3b commit 8cc11b75122c7cddc9fff1d92196177e61769772 @ludo committed Sep 7, 2011
View
2 Gemfile
@@ -6,6 +6,8 @@ gem 'jquery-rails', '1.0.13'
gem 'json', '1.5.4'
gem 'mysql2', '0.3.7'
gem 'rake', '0.9.2'
+gem 'twitter'
+gem 'twitter-text'
# Gems used only for assets and not required
# in production environments by default.
View
22 Gemfile.lock
@@ -30,6 +30,7 @@ GEM
activesupport (= 3.1.0)
activesupport (3.1.0)
multi_json (~> 1.0)
+ addressable (2.2.6)
arel (2.2.1)
bcrypt-ruby (3.0.0)
builder (3.0.0)
@@ -68,9 +69,16 @@ GEM
factory_girl_rails (1.2.0)
factory_girl (~> 2.1.0)
railties (>= 3.0.0)
+ faraday (0.7.4)
+ addressable (~> 2.2.6)
+ multipart-post (~> 1.1.0)
+ rack (>= 1.1.0, < 2)
+ faraday_middleware (0.7.0)
+ faraday (~> 0.7.3)
ffi (1.0.9)
gherkin (2.4.18)
json (>= 1.4.6)
+ hashie (1.1.0)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.13)
@@ -85,6 +93,8 @@ GEM
treetop (~> 1.4.8)
mime-types (1.16)
multi_json (1.0.3)
+ multi_xml (0.3.0)
+ multipart-post (1.1.3)
mysql2 (0.3.7)
nokogiri (1.5.0)
polyglot (0.3.2)
@@ -138,6 +148,7 @@ GEM
ffi (>= 1.0.7)
json_pure
rubyzip
+ simple_oauth (0.1.5)
sprockets (2.0.0)
hike (~> 1.2)
rack (~> 1.0)
@@ -149,6 +160,15 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
+ twitter (1.7.0)
+ faraday (~> 0.7.4)
+ faraday_middleware (~> 0.7.0)
+ hashie (~> 1.1.0)
+ multi_json (~> 1.0.0)
+ multi_xml (~> 0.3.0)
+ simple_oauth (~> 0.1.5)
+ twitter-text (1.4.9)
+ activesupport
tzinfo (0.3.29)
uglifier (1.0.3)
execjs (>= 0.3.0)
@@ -171,4 +191,6 @@ DEPENDENCIES
rake (= 0.9.2)
rspec-rails (= 2.6.1)
sass-rails (= 3.1.0)
+ twitter
+ twitter-text
uglifier (= 1.0.3)
View
3 app/assets/javascripts/main.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3 app/assets/stylesheets/main.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the main controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
24 app/controllers/main_controller.rb
@@ -0,0 +1,24 @@
+class MainController < ApplicationController
+ rescue_from Twitter::NotFound, :with => :username_not_found
+
+ def index
+ end
+
+ def hashtags
+
+ @screen_name = params[:screen_name]
+ @timeline = Twitter.user_timeline(@screen_name)
+ @hashtags = []
+
+ @timeline.each do |tweet|
+ @hashtags.concat Twitter::Extractor.extract_hashtags(tweet.text)
+ end
+
+ end
+
+
+ def username_not_found
+ redirect_to( { :action => :index }, :alert => 'username does not exist.')
+ end
+
+end
View
2 app/helpers/main_helper.rb
@@ -0,0 +1,2 @@
+module MainHelper
+end
View
4 app/views/layouts/application.html.erb
@@ -7,7 +7,9 @@
<%= csrf_meta_tags %>
</head>
<body>
-
+<% if flash[:alert] %>
+<p id="alert"><%= flash[:alert] %></p>
+<% end %>
<%= yield %>
</body>
View
5 app/views/main/hashtags.html.erb
@@ -0,0 +1,5 @@
+<h1>hash tags for <%= @screen_name %></h1>
+<ul>
+<% @hashtags.each do |hashtag| %>
+ <li>#<%= hashtag %></li>
+<% end %></ul>
View
8 app/views/main/index.html.erb
@@ -0,0 +1,8 @@
+<h1>Show Hashtags of user</h1>
+<p>
+<%= form_tag(:action => "hashtags") do %>
+ <p><%= label_tag(:screen_name,"twitter username") %></p>
+ <p><%= text_field_tag(:screen_name) %></p>
+ <p><%= submit_tag "search hashtags", :id => "submit", :name => "submit", :class => "form_submit" %></p>
+<% end -%>
+</p>
View
6 config/routes.rb
@@ -1,4 +1,8 @@
Twitstat::Application.routes.draw do
+ get "main/index"
+
+ post "main/hashtags"
+
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -48,7 +52,7 @@
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
- # root :to => 'welcome#index'
+ root :to => 'main#index'
# See how all your routes lay out with "rake routes"
View
19 spec/controllers/main_controller_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe MainController do
+
+ describe "GET 'index'" do
+ it "should be successful" do
+ get 'index'
+ response.should be_success
+ end
+ end
+
+ describe "GET 'hashtags'" do
+ it "should be successful" do
+ get 'hashtags'
+ response.should be_success
+ end
+ end
+
+end
View
15 spec/helpers/main_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the MainHelper. For example:
+#
+# describe MainHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe MainHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/views/main/hashtags.html.erb_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe "main/hashtags.html.erb" do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/views/main/index.html.erb_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe "main/index.html.erb" do
+ pending "add some examples to (or delete) #{__FILE__}"
+end

0 comments on commit 8cc11b7

Please sign in to comment.