lib/soapy_cake/client.rb in soapy_cake-1.23.0 vs lib/soapy_cake/client.rb in soapy_cake-1.23.1

- old
+ new

@@ -1,6 +1,8 @@ # frozen_string_literal: true +require 'net/http' + module SoapyCake class Client HEADERS = { 'Content-Type' => 'application/soap+xml;charset=UTF-8' }.freeze def initialize(opts = {}) @@ -61,12 +63,24 @@ end def http_response(request) logger.info("soapy_cake:request #{request}") if logger - url = "https://#{domain}#{request.path}" - HTTParty.post(url, headers: HEADERS, body: request.xml, timeout: NET_TIMEOUT).tap do |res| - raise RequestFailed, "Request failed with HTTP #{res.code}: #{res.body}" unless res.success? + http_request = Net::HTTP::Post.new(request.path, HEADERS) + http_request.body = request.xml + response = perform_http_request(http_request) + + unless response.is_a?(Net::HTTPSuccess) + raise RequestFailed, "Request failed with HTTP #{response.code}: #{response.body}" + end + + response.body + end + + def perform_http_request(http_request) + Net::HTTP.start(domain, + use_ssl: true, open_timeout: NET_TIMEOUT, read_timeout: NET_TIMEOUT) do |http| + http.request(http_request) end end end end