lib/soapy_cake/client.rb in soapy_cake-2.1.3 vs lib/soapy_cake/client.rb in soapy_cake-2.1.4
- old
+ new
@@ -1,6 +1,7 @@
# frozen_string_literal: true
+
require 'net/http'
module SoapyCake
class Client
HEADERS = { 'Content-Type' => 'application/soap+xml;charset=UTF-8' }.freeze
@@ -55,15 +56,27 @@
def logger
@logger ||= opts[:logger] || (defined?(::Rails) && ::Rails.logger)
end
+ def log_curl_command(request)
+ curl_headers = HEADERS.map { |k, v| "-H \"#{k}: #{v}\"" }.join(' ')
+ curl_body = request.xml
+ .tr("\n", '')
+ .gsub(/>\s*</, '><')
+ .sub(request.api_key, '{{{ INSERT API KEY }}}')
+
+ logger&.info("curl --data '#{curl_body}' #{curl_headers} https://#{domain}/#{request.path}")
+ end
+
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
response = perform_http_request(http_request)