Class: RoyalMailApi::RequestHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/royal_mail_api/request_handler.rb

Class Method Summary collapse

Class Method Details

.request(request, attrs = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/royal_mail_api/request_handler.rb', line 4

def request(request, attrs={})
  begin
    xml = build_xml(attrs)
    config.logger.info("CREATE SHIPMENT REQUEST: #{xml}")
    savon.call(request, xml: xml)
  rescue Savon::SOAPFault => e
    config.logger.error("CREATE SHIPMENT ERROR #{e.http.code}")
    config.logger.error("ERROR XML: #{e.xml}")
    raise RoyalMailApi::SoapError.new({
      xml: e.xml,
      error_code: e.http.code
    })
  end
end