lib/soapy_cake/client.rb in soapy_cake-2.2.7 vs lib/soapy_cake/client.rb in soapy_cake-2.3.0
- old
+ new
@@ -10,11 +10,11 @@
@opts = opts
@domain = fetch_opt(:domain) || raise(Error, 'Cake domain missing')
@api_key = fetch_opt(:api_key) || raise(Error, 'Cake API key missing')
@retry_count = fetch_opt(:retry_count, 4)
@write_enabled = ['yes', true].include?(fetch_opt(:write_enabled))
- @time_converter = TimeConverter.new(fetch_opt(:time_zone), fetch_opt(:time_offset))
+ @time_converter = TimeConverter.new(fetch_opt(:time_zone))
end
def xml_response?
opts[:xml_response] == true
end
@@ -51,10 +51,11 @@
opts.fetch(key, ENV.fetch("CAKE_#{key.to_s.upcase}", fallback))
end
def check_write_enabled!(request)
return if request.read_only? || write_enabled
+
raise Error, 'Writes not enabled (pass write_enabled: true or set CAKE_WRITE_ENABLED=yes)'
end
def with_retries(&block)
opts = { tries: retry_count + 1, on: [RateLimitError, SocketError], sleep: ->(n) { 3**n } }
@@ -78,16 +79,17 @@
def response_body(request)
request.opts[:response].presence || http_response(request)
end
def http_response(request)
- logger&.info("soapy_cake:request #{request}")
-
log_curl_command(request) if fetch_opt(:log_curl)
http_request = Net::HTTP::Post.new(request.path, HEADERS)
http_request.body = request.xml
+ t0 = Time.now
response = perform_http_request(http_request)
+ response_time = Time.now - t0
+ logger&.info("soapy_cake:request #{request} took: #{response_time.round(2)} s")
unless response.is_a?(Net::HTTPSuccess)
raise RequestFailed.new(
"Request failed with HTTP #{response.code}",
response_body: response.body