lib/tickethub/request.rb in tickethub-0.3.49 vs lib/tickethub/request.rb in tickethub-0.3.50

- old
+ new

@@ -1,22 +1,21 @@ require 'securerandom' module Tickethub class Request - SAFE_TO_RETRY = [408, 502, 503, 504].freeze - MAXIMUM_RETRIES = 3.freeze - attr_reader :options, :format, :url attr_accessor :params, :body, :method, :headers # Connection options - attr_accessor :proxy, :user, :password, :auth_type, :timeout, :ssl_options + attr_accessor :proxy, :user, :password, :auth_type, :timeout, :retries, :ssl_options def initialize(url, options = {}) @url = url.to_s @id = SecureRandom.uuid + @retries = 3 + @timeout = 10 @options = options @options.each do |key, val| method = "#{key}=" send(method, val) if respond_to?(method) @@ -57,27 +56,23 @@ def path uri.path end - def execute(retries = 0) + def execute if encoded? result = connection.send(method, path, encoded, build_headers) else result = connection.send(method, query_path, build_headers) end Response.new(result) - rescue TimeoutError => err - raise if retries == MAXIMUM_RETRIES - 1 - execute retries + 1 - rescue ConnectionError => err - raise if ! SAFE_TO_RETRY.member?(err.response.code) || retries == MAXIMUM_RETRIES - 1 - execute retries + 1 + rescue TimeoutError, ServerError => err + raise err if (@retries -= 1) == 0 + execute rescue Redirection => error raise error unless error.response['Location'] - location = URI.parse(error.response['Location']) # Path is relative unless location.host location = URI.join(uri, location) \ No newline at end of file