Class: Starapi::SoapServiceFacade::Base
- Inherits:
-
Object
- Object
- Starapi::SoapServiceFacade::Base
- Defined in:
- lib/starapi/soap_service_facade/base.rb
Direct Known Subclasses
Instance Method Summary collapse
- #construct_envelope(&block) ⇒ Object
- #handle_error(response) ⇒ Object
- #process_response(response) ⇒ Object
Instance Method Details
#construct_envelope(&block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/starapi/soap_service_facade/base.rb', line 7 def construct_envelope(&block) Nokogiri::XML::Builder.new do |xml| xml.Envelope("xmlns:soap12" => "http://www.w3.org/2003/05/soap-envelope", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema") do xml.parent.namespace = xml.parent.namespace_definitions.first xml['soap12'].Body(&block) end end end |
#handle_error(response) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/starapi/soap_service_facade/base.rb', line 28 def handle_error(response) xml = Nokogiri::XML(response.body) xpath = '/soap:Envelope/soap:Body/soap:Fault//soap:Text' msg = xml.xpath(xpath).text # TODO: Capture any app-specific exception messages here. # For example, if the server returns a Fault when a search # has no results, you might rather return an empty array. raise SoapServiceFacade::SoapError.new("Error from server: #{msg}") end |
#process_response(response) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/starapi/soap_service_facade/base.rb', line 18 def process_response(response) @last_response = response if response.body =~ /soap:Fault/ then handle_error(response) else return response end end |