class Savon::SOAP::XML
Savon::SOAP::XML¶ ↑
Represents the SOAP request XML. Contains various global and per request/instance settings like the SOAP version, header, body and namespaces.
Constants
- SchemaTypes
XML Schema Type namespaces.
Attributes
Sets whether all local elements should be namespaced.
Accessor for the SOAP endpoint
.
Sets the SOAP envelope namespace.
Sets the SOAP header
Hash.
Accessor for the SOAP input
tag.
Accessor for the default namespace URI.
Sets the default namespace identifier.
Sets the namespaces
Hash.
Accessor for the Savon::WSSE
object.
Accepts an XML String and lets you specify a completely custom request body.
Public Class Methods
Accepts an endpoint
, an input
tag and a SOAP body
.
# 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
Public Instance Methods
Returns whether all local elements should be namespaced. Might be set to :qualified, but defaults to :unqualified.
# File lib/savon/soap/xml.rb, line 88 def element_form_default @element_form_default ||= :unqualified end
Returns the SOAP envelope namespace. Uses the global namespace if set Defaults to :env.
# File lib/savon/soap/xml.rb, line 63 def env_namespace @env_namespace ||= Savon.env_namespace.nil? ? :env : Savon.env_namespace end
Returns the SOAP header
. Defaults
to an empty Hash.
# File lib/savon/soap/xml.rb, line 55 def header @header ||= Savon.soap_header.nil? ? {} : Savon.soap_header end
Returns the default namespace identifier.
# File lib/savon/soap/xml.rb, line 82 def namespace_identifier @namespace_identifier ||= :wsdl end
Returns the namespaces
. Defaults to a Hash containing the SOAP envelope namespace.
# 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
Returns the XML for a SOAP request.
# File lib/savon/soap/xml.rb, line 114 def to_xml @xml ||= tag(builder, :Envelope, complete_namespaces) do |xml| tag(xml, :Header) { xml << header_for_xml } unless header_for_xml.empty? input.nil? ? tag(xml, :Body) : tag(xml, :Body) { xml.tag!(*input) { xml << body_to_xml } } end end
Returns the SOAP version
. Defaults
to Savon.soap_version
.
# File lib/savon/soap/xml.rb, line 47 def version @version ||= Savon.soap_version end
Sets the SOAP version
.
# 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
Accepts a block
and yields a Builder::XmlMarkup
object to let you create custom XML.
# File lib/savon/soap/xml.rb, line 106 def xml @xml = yield builder if block_given? end
Private Instance Methods
Returns a new Builder::XmlMarkup
object.
# File lib/savon/soap/xml.rb, line 124 def builder builder = Builder::XmlMarkup.new builder.instruct! builder end
Returns the complete Hash of namespaces.
# File lib/savon/soap/xml.rb, line 138 def complete_namespaces defaults = SchemaTypes.dup defaults["xmlns:#{namespace_identifier}"] = namespace if namespace defaults.merge namespaces end
Expects a builder xml
instance, a tag name
and
accepts optional namespaces
and a block to create an XML tag.
# File lib/savon/soap/xml.rb, line 132 def tag(xml, name, namespaces = {}, &block) return xml.tag! name, namespaces, &block if env_namespace.blank? xml.tag! env_namespace, name, namespaces, &block end
Returns the WSSE header or an empty String in case WSSE was not set.
# File lib/savon/soap/xml.rb, line 150 def wsse_header wsse.respond_to?(:to_xml) ? wsse.to_xml : "" end