Sha256: f35748ba367aa7c0b640dca03108b571962558f0add9021ecff0f281858782e0

Contents?: true

Size: 1.27 KB

Versions: 11

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require 'cgi'
require 'rest-client'

module Roqua
  module Healthy
    module Oru
      class Client
        def self.execute(url, data, timeout:)
          Roqua::Healthy.convert_generic_errors_to_healthy_errors do
            deliver_data(url, data, timeout: timeout)
          end
        end

        def self.deliver_data(url, data, timeout:)
          xml = CGI.escape(data.to_xml)
          RestClient::Request.execute(
            method: :post,
            url: url.to_s,
            payload: xml,
            headers: {content_type: 'text/xml'},
            timeout: timeout.to_i
          ) do |response, _request, _result|

            xml_response = Hash.from_xml(response.body)

            if response.code == 200 && xml_response['oru']['status'] == 'ACK'
              response.body
            else
              handle_error(response, xml_response)
            end
          end
        end

        def self.handle_error(response, xml_response)
          error = xml_response.dig('oru', 'error')
          raise ::Roqua::Healthy::ERRORS[error], error if ::Roqua::Healthy::ERRORS[error]
          raise ::Roqua::Healthy::NACK, error if error.present?
          raise ::Roqua::Healthy::UnknownFailure, response.body
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
roqua-healthy-1.5.11 lib/roqua/healthy/oru/client.rb
roqua-healthy-1.5.10 lib/roqua/healthy/oru/client.rb
roqua-healthy-1.5.9 lib/roqua/healthy/oru/client.rb
roqua-healthy-1.5.8 lib/roqua/healthy/oru/client.rb
roqua-healthy-1.5.7 lib/roqua/healthy/oru/client.rb
roqua-healthy-1.5.6 lib/roqua/healthy/oru/client.rb
roqua-healthy-1.5.5 lib/roqua/healthy/oru/client.rb
roqua-healthy-1.5.4 lib/roqua/healthy/oru/client.rb
roqua-healthy-1.5.3 lib/roqua/healthy/oru/client.rb
roqua-healthy-1.5.2 lib/roqua/healthy/oru/client.rb
roqua-healthy-1.5.1 lib/roqua/healthy/oru/client.rb