lib/soapy_cake/client.rb in soapy_cake-1.16.1 vs lib/soapy_cake/client.rb in soapy_cake-1.16.2

- old
+ new

@@ -1,8 +1,8 @@ module SoapyCake class Client - attr_reader :domain, :api_key, :time_converter + 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') @@ -17,11 +17,11 @@ opts[:xml_response] == true end protected - attr_reader :opts + attr_reader :domain, :api_key, :time_converter, :opts def run(request) request.api_key = api_key request.time_converter = time_converter @@ -30,27 +30,19 @@ end private def response_body(request) - if request.opts[:response].present? - request.opts[:response] - else - http_response(request) - end + request.opts[:response].presence || http_response(request) end def http_response(request) url = "https://#{domain}#{request.path}" - http_response = HTTParty.post(url, headers: headers, body: request.xml, timeout: NET_TIMEOUT) + http_response = HTTParty.post(url, headers: HEADERS, body: request.xml, timeout: NET_TIMEOUT) fail RequestFailed, "Request failed with HTTP #{http_response.code}: " \ "#{http_response.body}" unless http_response.success? http_response - end - - def headers - { 'Content-Type' => 'application/soap+xml;charset=UTF-8' } end end end