-
-
Save surendrans/5262174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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