Class: Roqua::Healthy::Oru::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/roqua/healthy/oru/client.rb

Class Method Summary collapse

Class Method Details

.deliver_data(url, data, timeout:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/roqua/healthy/oru/client.rb', line 16

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

.execute(url, data, timeout:) ⇒ Object



10
11
12
13
14
# File 'lib/roqua/healthy/oru/client.rb', line 10

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

.handle_error(response, xml_response) ⇒ Object

Raises:



36
37
38
39
40
41
# File 'lib/roqua/healthy/oru/client.rb', line 36

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