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

body[RW]

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.

element_form_default[W]

Sets whether all local elements should be namespaced.

endpoint[RW]

Accessor for the SOAP endpoint.

env_namespace[W]

Sets the SOAP envelope namespace.

header[W]

Sets the SOAP header Hash.

input[RW]

Accessor for the SOAP input tag.

namespace[RW]

Accessor for the default namespace URI.

namespace_identifier[W]

Sets the default namespace identifier.

namespaces[W]

Sets the namespaces Hash.

wsse[RW]

Accessor for the Savon::WSSE object.

xml[W]

Accepts an XML String and lets you specify a completely custom request body.

Public Class Methods

new(endpoint = nil, input = nil, body = nil) click to toggle source

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

element_form_default() click to toggle source

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
env_namespace() click to toggle source

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
header() click to toggle source

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
namespace_identifier() click to toggle source

Returns the default namespace identifier.

# File lib/savon/soap/xml.rb, line 82
def namespace_identifier
  @namespace_identifier ||= :wsdl
end
namespaces() click to toggle source

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
to_xml() click to toggle source

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
version() click to toggle source

Returns the SOAP version. Defaults to Savon.soap_version.

# File lib/savon/soap/xml.rb, line 47
def version
  @version ||= Savon.soap_version
end
version=(version) click to toggle source

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
xml() { |builder| ... } click to toggle source

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

body_to_xml() click to toggle source

Returns the SOAP body as an XML String.

# File lib/savon/soap/xml.rb, line 155
def body_to_xml
  return body.to_s unless body.kind_of? Hash
  Gyoku.xml body, :element_form_default => element_form_default, :namespace => namespace_identifier
end
builder() click to toggle source

Returns a new Builder::XmlMarkup object.

# File lib/savon/soap/xml.rb, line 124
def builder
  builder = Builder::XmlMarkup.new
  builder.instruct!
  builder
end
complete_namespaces() click to toggle source

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
header_for_xml() click to toggle source

Returns the SOAP header as an XML String.

# File lib/savon/soap/xml.rb, line 145
def header_for_xml
  @header_for_xml ||= Gyoku.xml(header) + wsse_header
end
tag(xml, name, namespaces = {}, &block) click to toggle source

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
wsse_header() click to toggle source

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