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

Namespace =

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" }
Versions =

Supported SOAP versions.

[1, 2]
DateTimeFormat =

SOAP xs:dateTime format.

"%Y-%m-%dT%H:%M:%SZ"
DateTimeRegexp =

SOAP xs:dateTime Regexp.

/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/
@@version =

The global SOAP version.

1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation, endpoint) ⇒ SOAP

Initialzes the SOAP object.



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

def initialize(operation, endpoint)
  @action, @input = operation[:action], operation[:input]
  @endpoint = endpoint.kind_of?(URI) ? endpoint : URI(endpoint)
  @builder = Builder::XmlMarkup.new
end

Instance Attribute Details

#actionObject

Returns the SOAP action.



76
77
78
# File 'lib/savon/soap.rb', line 76

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.



102
103
104
# File 'lib/savon/soap.rb', line 102

def body=(value)
  @body = value
end

#endpointObject

Accessor for the SOAP endpoint.



89
90
91
# File 'lib/savon/soap.rb', line 89

def endpoint
  @endpoint
end

#headerObject

Returns the SOAP header. Defaults to an empty Hash.



96
97
98
# File 'lib/savon/soap.rb', line 96

def header
  @header ||= {}
end

#inputObject

Returns the SOAP input.



84
85
86
# File 'lib/savon/soap.rb', line 84

def input
  @input ||= ""
end

#namespacesObject

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



110
111
112
# File 'lib/savon/soap.rb', line 110

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

#wsse=(value) ⇒ Object (writeonly)

Sets the WSSE options.



70
71
72
# File 'lib/savon/soap.rb', line 70

def wsse=(value)
  @wsse = value
end

Class Method Details

.headerObject

Returns the global SOAP header. Defaults to an empty Hash.



46
47
48
# File 'lib/savon/soap.rb', line 46

def self.header
  @@header ||= {}
end

.header=(header) ⇒ Object

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



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

def self.header=(header)
  @@header = header
end

.namespacesObject

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



58
59
60
# File 'lib/savon/soap.rb', line 58

def self.namespaces
  @@namespaces ||= {}
end

.namespaces=(namespaces) ⇒ Object

Sets the global namespaces. Expected to be a Hash containing the namespaces (keys) and the corresponding URI’s (values).



52
53
54
# File 'lib/savon/soap.rb', line 52

def self.namespaces=(namespaces)
  @@namespaces = namespaces if namespaces.kind_of? Hash
end

.versionObject

Returns the global SOAP version.



30
31
32
# File 'lib/savon/soap.rb', line 30

def self.version
  @@version
end

.version=(version) ⇒ Object

Sets the global SOAP version.



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

def self.version=(version)
  @@version = version if Versions.include? version
end

Instance Method Details

#namespace=(namespace) ⇒ Object

Convenience method for setting the “xmlns:wsdl” namespace.



115
116
117
# File 'lib/savon/soap.rb', line 115

def namespace=(namespace)
  namespaces["xmlns:wsdl"] = namespace
end

#to_xmlObject

Returns the SOAP envelope XML.



130
131
132
133
134
135
136
137
138
# File 'lib/savon/soap.rb', line 130

def to_xml
  unless @xml_body
    @xml_body = @builder.env :Envelope, all_namespaces do |xml|
      xml.env(:Header) { xml << all_header } unless all_header.empty?
      xml_body xml
    end
  end
  @xml_body
end

#versionObject

Returns the SOAP version. Defaults to the global default.



125
126
127
# File 'lib/savon/soap.rb', line 125

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

#version=(version) ⇒ Object

Sets the SOAP version.



120
121
122
# File 'lib/savon/soap.rb', line 120

def version=(version)
  @version = version if Versions.include? version
end