Class: Savon::SOAP::XML

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

Overview

Savon::SOAP::XML

Represents the SOAP request XML. Contains various global and per request/instance settings like the SOAP version, header, body and namespaces.

Constant Summary collapse

SchemaTypes =

XML Schema Type namespaces.

{
  "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint = nil, input = nil, body = nil) ⇒ XML

Accepts an endpoint, an input tag and a SOAP body.



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

def initialize(endpoint = nil, input = nil, body = nil)
  self.endpoint = endpoint if endpoint
  self.input = input if input
  self.body = body if body
end

Instance Attribute Details

#bodyObject

Accessor for the SOAP body. Expected to be a Hash that can be translated to XML via Gyoku.xml or any other Object responding to to_s.



130
131
132
# File 'lib/savon/soap/xml.rb', line 130

def body
  @body
end

#element_form_defaultObject

Returns whether all local elements should be namespaced. Might be set to :qualified, but defaults to :unqualified.



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

def element_form_default
  @element_form_default ||= :unqualified
end

#endpointObject

Accessor for the SOAP endpoint.



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

def endpoint
  @endpoint
end

#env_namespaceObject

Returns the SOAP envelope namespace. Uses the global namespace if set Defaults to :env.



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

def env_namespace
  @env_namespace ||= Savon.env_namespace.nil? ? :env : Savon.env_namespace
end

#headerObject

Returns the SOAP header. Defaults to an empty Hash.



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

def header
  @header ||= Savon.soap_header.nil? ? {} : Savon.soap_header
end

#inputObject

Accessor for the SOAP input tag.



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

def input
  @input
end

#namespaceObject

Accessor for the default namespace URI.



123
124
125
# File 'lib/savon/soap/xml.rb', line 123

def namespace
  @namespace
end

#namespace_identifierObject

Returns the default namespace identifier.



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

def namespace_identifier
  @namespace_identifier ||= :wsdl
end

#namespacesObject

Returns the namespaces. Defaults to a Hash containing the SOAP envelope namespace.



71
72
73
74
75
76
# File 'lib/savon/soap/xml.rb', line 71

def namespaces
  @namespaces ||= begin
    key = env_namespace.blank? ? "xmlns" : "xmlns:#{env_namespace}"
    { key => SOAP::Namespace[version] }
  end
end

#wsseObject

Accessor for the Savon::WSSE object.



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

def wsse
  @wsse
end

#xmlObject

Accepts a block and yields a Builder::XmlMarkup object to let you create custom XML.



133
134
135
# File 'lib/savon/soap/xml.rb', line 133

def xml
  @xml = yield builder if block_given?
end

Instance Method Details

#namespace_by_uri(uri) ⇒ Object



78
79
80
81
82
83
# File 'lib/savon/soap/xml.rb', line 78

def namespace_by_uri(uri)
  namespaces.each do |candidate_identifier, candidate_uri|
    return candidate_identifier.gsub(/^xmlns:/, '') if candidate_uri == uri
  end
  nil
end

#to_xmlObject

Returns the XML for a SOAP request.



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/savon/soap/xml.rb', line 141

def to_xml
  @xml ||= tag(builder, :Envelope, complete_namespaces) do |xml|
    tag(xml, :Header) { xml << header_for_xml } unless header_for_xml.empty?

    if input.nil?
      tag(xml, :Body)
    else
      tag(xml, :Body) { xml.tag!(*add_namespace_to_input) { xml << body_to_xml } }
    end
  end
end

#typesObject



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

def types
  @types ||= {}
end

#use_namespace(path, uri) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/savon/soap/xml.rb', line 89

def use_namespace(path, uri)
  @internal_namespace_count ||= 0

  unless identifier = namespace_by_uri(uri)
    identifier = "ins#{@internal_namespace_count}"
    namespaces["xmlns:#{identifier}"] = uri
    @internal_namespace_count += 1
  end

  used_namespaces[path] = identifier
end

#used_namespacesObject



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

def used_namespaces
  @used_namespaces ||= {}
end

#versionObject

Returns the SOAP version. Defaults to Savon.soap_version.



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

def version
  @version ||= Savon.soap_version
end

#version=(version) ⇒ Object

Sets the SOAP version.

Raises:

  • (ArgumentError)


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

def version=(version)
  raise ArgumentError, "Invalid SOAP version: #{version}" unless SOAP::Versions.include? version
  @version = version
end