module Savon # == Savon::SOAP # # Represents the SOAP parameters and envelope. class SOAP # SOAP namespaces by SOAP version. SOAPNamespace = { 1 => "http://schemas.xmlsoap.org/soap/envelope/", 2 => "http://www.w3.org/2003/05/soap-envelope" } # Content-Types by SOAP version. ContentType = { 1 => "text/xml", 2 => "application/soap+xml" } # The default SOAP version. @version = 1 class << self # Returns the default SOAP version. attr_reader :version # Sets the default SOAP version. def version=(version) @version = version if Savon::SOAPVersions.include? version end end # Expects an +action_map+ containing the name of the SOAP action and input. def initialize(action_map) @action = action_map[:name] @input = action_map[:input] end # Sets the WSSE options. attr_writer :wsse # Accessor for the SOAP action. attr_accessor :action # Sets the 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. attr_writer :header # Returns the SOAP header. Defaults to an empty Hash. def header @header ||= {} end # 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. attr_writer :body # Sets the namespaces. Expected to be a Hash containing the namespaces # (keys) and the corresponding URI's (values). attr_writer :namespaces # Returns the namespaces. A Hash containing the namespaces (keys) and # the corresponding URI's (values). def namespaces @namespaces ||= { "xmlns:env" => SOAPNamespace[version] } end # Sets the SOAP version. def version=(version) @version = version if Savon::SOAPVersions.include? version end # Returns the SOAP version. Defaults to the global default. def version @version ||= self.class.version end # Returns the SOAP envelope XML. 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 private # Returns the WSSE header or an empty String in case WSSE was not set. def wsse_header return "" unless @wsse.respond_to? :header @wsse.header end end end