Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Created May 9, 2009 09:33
Show Gist options
  • Save Sixeight/109202 to your computer and use it in GitHub Desktop.
Save Sixeight/109202 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'rubygems'
require 'typhoeus'
require 'json'
require 'time'
require 'net/http'
class Twitter
include Typhoeus
remote_defaults :on_success => lambda {|responce| JSON.parse(responce.body) },
:on_failure => lambda {|responce| responce.code.inspect },
:base_uri => 'http://search.twitter.com'
define_remote_method :search, :path => '/search.json'
define_remote_method :trends, :path => '/trends/:time_frame.json'
end
start = Time.now
tweets = Twitter.search(:params => { :q => 'railsconf' })
period = Time.now - start
puts "Typhoeus total: #{period}"
# tweets['results'].each do |tweet|
# puts "(#{Time.parse(tweet['created_at']).strftime("%m-%d %H:%M")}) #{tweet['from_user']}: #{tweet['text']}"
# end
Net::HTTP.version_1_2
start = Time.now
Net::HTTP.start('search.twitter.com', 80) do |http|
response = http.get('/search.json?q=railsconf')
body = JSON.parse(response.body)
end
period = Time.now - start
puts "Net;HTTP total: #{period}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment