Skip to content

Instantly share code, notes, and snippets.

@mrichie
Forked from Fryguy/gist:4149410
Created January 25, 2013 01:39
Show Gist options
  • Save mrichie/4630850 to your computer and use it in GitHub Desktop.
Save mrichie/4630850 to your computer and use it in GitHub Desktop.
require "vcr"
require "net/http"
VCR.configure do |c|
c.cassette_library_dir = '/tmp'
c.hook_into :webmock
c.default_cassette_options = {
record: :once
}
end
# forgive me Google ;)
module ThirdPartyApi
def self.query
threads = []
queries = 200.times.map { |n| "query-#{n}" }
queries.each_slice(5) do |sliced_queries|
threads << Thread.new do
sliced_queries.each do |q|
Net::HTTP.get("google.com", "?q=#{q}")
end
end
end
threads.map(&:join)
end
end
VCR.use_cassette("google_search") do
ThirdPartyApi.query
puts "success!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment