Skip to content

Instantly share code, notes, and snippets.

@surendrans
Forked from spritle/parallel_fetch.rb
Created March 28, 2013 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save surendrans/5262174 to your computer and use it in GitHub Desktop.
Save surendrans/5262174 to your computer and use it in GitHub Desktop.
require 'typhoeus'
require "json"
url1 = "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=dchelimsky&count=20"
url2 = "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=spritlesoftware&count=5"
url3 = "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=TouchVu&count=10"
url4 = "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=ibmmobile&count=1"
hydra = Typhoeus::Hydra.new
def print_tweet(url, raw_response_body)
puts url
# json_data = JSON.parse(raw_response_body)
puts JSON.parse(raw_response_body)[0]["text"]
puts "---------"
end
first_request = Typhoeus::Request.new(url1)
first_request.on_complete do |response|
print_tweet(url1, response.body)
end
second_request = Typhoeus::Request.new(url2)
second_request.on_complete do |response|
print_tweet(url2, response.body)
end
third_request = Typhoeus::Request.new(url3)
third_request.on_complete do |response|
print_tweet(url3, response.body)
end
fourth_request = Typhoeus::Request.new(url4)
fourth_request.on_complete do |response|
print_tweet(url4, response.body)
end
hydra.queue first_request
hydra.queue second_request
hydra.queue third_request
hydra.queue fourth_request
hydra.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment