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