Skip to content

Instantly share code, notes, and snippets.

@tiagomatos
Last active October 28, 2016 16:52
Show Gist options
  • Select an option

  • Save tiagomatos/59dba5b55591b98879baf356f26d739e to your computer and use it in GitHub Desktop.

Select an option

Save tiagomatos/59dba5b55591b98879baf356f26d739e to your computer and use it in GitHub Desktop.
require 'uri'
require 'net/http'
require 'openssl'
require "benchmark"
HOST = 'api.jumpseller.com'
# uri = URI.parse("http://#{HOST}/landing/pricing?currency=CLP")
uri = URI.parse("http://#{HOST}/v1/products/{product_id}.json?login=XXX&authtoken=XXX")
http = Net::HTTP.new(uri.host, uri.port)
# if we are using a HTTPS URL (production use) config the uri.
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
count_ok = 0
count_fail = 0
time_all = Benchmark.realtime do
for i in 0..30
time = Benchmark.realtime do
p "In call: #{Time.now.to_f}"
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
p code = response.code
code == "200" ? (count_ok+=1) : (count_fail+=1)
sleep 0.50
unless code == "200"
p response.body
p "retry in:" + response["Retry-After"] if code == "403" && response["Retry-After"]
end
end
puts "#{time.round(3)} seconds."
end
end
p "count_ok: #{count_ok}"
p "count_fail: #{count_fail}"
p "run in #{time_all} seconds."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment