Skip to content

Commit

Permalink
use typhoeus
Browse files Browse the repository at this point in the history
  • Loading branch information
siuying committed Jan 13, 2010
1 parent 2f1b297 commit 9724ac5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gems
@@ -1,3 +1,3 @@
sinatra
json
httpclient
typhoeus
16 changes: 8 additions & 8 deletions lib/green/controller.rb
@@ -1,8 +1,7 @@
require 'sinatra/base'
$KCODE = 'UTF8'
require 'logger'
require 'httpclient'

require 'typhoeus'

module Sinatra
module Green
Expand All @@ -13,7 +12,6 @@ def self.registered(app)
app.before do
@log = Logger.new($stdout)

@client = HTTPClient.new
begin
tweet(options.search_terms.join(' OR '))
rescue StandardError => e
Expand Down Expand Up @@ -48,11 +46,7 @@ def tweet(term)
last_tweet = Tweet.first(:order => [:twitter_id.desc]).twitter_id rescue 0
last_tweet ||= 0

rpp = 100
query = { 'q' => term, 'rpp' => rpp, 'since_id' => last_tweet }
header = {'User-Agent' => 'stopxrl.heroku.com'}

res = JSON.parse(@client.get_content("http://search.twitter.com/search.json", query, header))
res = JSON.parse(open("http://search.twitter.com/search.json", term, last_tweet))
results = res['results']
results.each do |t|
#@log.info("tweet: #{t.inspect}")
Expand Down Expand Up @@ -92,6 +86,12 @@ def partial(template, *args)
end
end

def open(url, term, last_tweet)
query = { :q => term, :rpp => "100", :since_id => last_tweet }
response = Typhoeus::Request.post(url, :timeout => 15000, :cache_timeout => 60, :params => query)
response.body
end

#prepare text for html output
# add a tag to link
# link hashtag
Expand Down

0 comments on commit 9724ac5

Please sign in to comment.