Class: Savon::SOAP

Inherits:
Object show all
Defined in:
lib/savon/soap.rb

Overview

Savon::SOAP

Represents the SOAP parameters and envelope.

Constant Summary collapse

SOAPNamespace =

SOAP namespaces by SOAP version.

{
  1 => "http://schemas.xmlsoap.org/soap/envelope/",
  2 => "http://www.w3.org/2003/05/soap-envelope"
}
ContentType =

Content-Types by SOAP version.

{ 1 => "text/xml", 2 => "application/soap+xml" }

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action_map) ⇒ SOAP

Expects an action_map containing the name of the SOAP action and input.



33
34
35
36
# File 'lib/savon/soap.rb', line 33

def initialize(action_map)
  @action = action_map[:name]
  @input = action_map[:input]
end

Class Attribute Details

.versionObject

Returns the default SOAP version.



23
24
25
# File 'lib/savon/soap.rb', line 23

def version
  @version
end

Instance Attribute Details

#actionObject

Accessor for the SOAP action.



42
43
44
# File 'lib/savon/soap.rb', line 42

def action
  @action
end

#body=(value) ⇒ Object (writeonly)

Sets the SOAP body. Expected to be a Hash that can be translated to XML via Hash.to_soap_xml or any other Object responding to to_s.



55
56
57
# File 'lib/savon/soap.rb', line 55

def body=(value)
  @body = value
end

#headerObject

Returns the SOAP header. Defaults to an empty Hash.



49
50
51
# File 'lib/savon/soap.rb', line 49

def header
  @header ||= {}
end

#namespacesObject

Returns the namespaces. A Hash containing the namespaces (keys) and the corresponding URI’s (values).



63
64
65
# File 'lib/savon/soap.rb', line 63

def namespaces
  @namespaces ||= { "xmlns:env" => SOAPNamespace[version] }
end

#wsse=(value) ⇒ Object (writeonly)

Sets the WSSE options.



39
40
41
# File 'lib/savon/soap.rb', line 39

def wsse=(value)
  @wsse = value
end

Instance Method Details

#to_xmlObject

Returns the SOAP envelope XML.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/savon/soap.rb', line 78

def to_xml
  unless @xml_body
    builder = Builder::XmlMarkup.new

    @xml_body = builder.env :Envelope, namespaces do |xml|
      xml.env(:Header) do
        xml << (header.to_soap_xml rescue header.to_s) + wsse_header
      end
      xml.env(:Body) do
        xml.wsdl(@input.to_sym) do
          xml << (@body.to_soap_xml rescue @body.to_s)
        end
      end
    end
  end
  @xml_body
end

#versionObject

Returns the SOAP version. Defaults to the global default.



73
74
75
# File 'lib/savon/soap.rb', line 73

def version
  @version ||= self.class.version
end

#version=(version) ⇒ Object

Sets the SOAP version.



68
69
70
# File 'lib/savon/soap.rb', line 68

def version=(version)
  @version = version if Savon::SOAPVersions.include? version
end