Class: Temando::Api::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Configurable
Defined in:
lib/temando/api/base.rb

Overview

Provides the low-level SOAP formatting functionality.

Direct Known Subclasses

GetQuotesByRequest

Constant Summary collapse

TEMANDO_NAMESPACE =
"http://api.temando.com/schema/2009_06/server.xsd"

Instance Method Summary collapse

Instance Method Details

#soap_boilerplate(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/temando/api/base.rb', line 14

def soap_boilerplate(&block)
  data = Nokogiri::XML::Builder.new do |xml|
    xml.Envelope("xmlns:soapenv" => "http://schemas.xmlsoap.org/soap/envelope/",
                             "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
                             "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance") do

      # Ensure that the "Envelope" namespace absolutely must be soapenv, otherwise we will get soap:VersionMismatch errors
      xml.parent.namespace = xml.parent.namespace_definitions.find { |x| x.prefix == 'soapenv' }
      xml['soapenv'].Header do
        xml.Security("xmlns:wsse" => "http://schemas.xmlsoap.org/ws/2002/04/secext") do
          xml.parent.namespace = xml.parent.namespace_definitions.find { |x| x.prefix == 'wsse' }
          xml['wsse'].UsernameToken do
            xml['wsse'].Username Temando::Api::Base.username
            xml['wsse'].Password Temando::Api::Base.password
          end
        end
      end
      xml['soapenv'].Body(&block)
    end
  end

  data.to_xml(:indent => 2, :encoding => 'UTF-8')
end