Skip to content

Instantly share code, notes, and snippets.

@tiagomatos
Last active February 25, 2018 12:32
Show Gist options
  • Save tiagomatos/22a2526f100901c35fbbc0bb38df5736 to your computer and use it in GitHub Desktop.
Save tiagomatos/22a2526f100901c35fbbc0bb38df5736 to your computer and use it in GitHub Desktop.
Centry - Jumpseller Integration
def do_request_login(method, resource, data)
url = "#{ENV['JUMPSELLER_API_BASE_URL']}#{resource}?#{{login: integration_config.login, authtoken: integration_config.authtoken}.to_query}"
for i in 1..10 do
perform_request(method, url, data)
if resp.code >= 200 and resp.code < 300 or resp.code == 404
return resp
elsif resp.nil? or resp.code == 403 # and message "Rate Limit Exceeded"?
sleep 1.0
else
raise "Error #{resp.code}: #{resp.inspect}"
end
end
raise "Rate limit exceeded"
end
def perform_request(method, url, data)
resp = case method
when :get then HTTParty.get(url)
when :post then HTTParty.post( url, {:body => data.to_json, :headers => {'Content-Type' => 'application/json'}, :timeout => 400, :verify => false})
when :put then HTTParty.put( url, {:body => data.to_json, :headers => {'Content-Type' => 'application/json'}, :timeout => 400, :verify => false})
when :delete then HTTParty.delete(url, {:body => data.to_json, :headers => {'Content-Type' => 'application/json'}, :timeout => 400, :verify => false})
end
sleep 0.5
end
@tiagomatos
Copy link
Author

After each get/post/put/delete request, there should be a sleep.

This will ensure you do not cross the rate limits, on every 2 calls, hence on the short term, get IP-banned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment