class Roqua::Healthy::Oru::Client

Public Class Methods

deliver_data(url, data, timeout:) click to toggle source
# 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:) click to toggle source
# 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) click to toggle source
# File lib/roqua/healthy/oru/client.rb, line 35
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