lib/soapy_cake/client.rb in soapy_cake-1.20.0 vs lib/soapy_cake/client.rb in soapy_cake-1.21.0
- old
+ new
@@ -3,30 +3,36 @@
HEADERS = { 'Content-Type' => 'application/soap+xml;charset=UTF-8' }.freeze
def initialize(opts = {})
@domain = opts.fetch(:domain, ENV['CAKE_DOMAIN']) || fail(Error, 'Cake domain missing')
@api_key = opts.fetch(:api_key, ENV['CAKE_API_KEY']) || fail(Error, 'Cake API key missing')
+ @retry_count = opts.fetch(:retry_count, ENV['CAKE_RETRY_COUNT']) || 4
- time_offset = opts.fetch(:time_offset, ENV['CAKE_TIME_OFFSET'])
- time_zone = opts.fetch(:time_zone, ENV['CAKE_TIME_ZONE'])
- @time_converter = TimeConverter.new(time_zone, time_offset)
+ @time_converter = TimeConverter.new(
+ opts.fetch(:time_zone, ENV['CAKE_TIME_ZONE']),
+ opts.fetch(:time_offset, ENV['CAKE_TIME_OFFSET'])
+ )
@opts = opts
end
def xml_response?
opts[:xml_response] == true
end
protected
- attr_reader :domain, :api_key, :time_converter, :opts, :logger
+ attr_reader :domain, :api_key, :time_converter, :opts, :logger, :retry_count
def run(request)
request.api_key = api_key
request.time_converter = time_converter
- Retryable.retryable(tries: 5, on: RateLimitError, sleep: -> (n) { 3**n }) do
+ Retryable.retryable(
+ tries: retry_count + 1,
+ on: [RateLimitError, SocketError],
+ sleep: -> (n) { 3**n }
+ ) do
response = Response.new(response_body(request), request.short_response?, time_converter)
xml_response? ? response.to_xml : response.to_enum
end
end