lib/apricoteatsgorilla/apricoteatsgorilla.rb in rubiii-apricoteatsgorilla-0.5.5 vs lib/apricoteatsgorilla/apricoteatsgorilla.rb in rubiii-apricoteatsgorilla-0.5.6
- old
+ new
@@ -8,10 +8,16 @@
# SOAP messages (XML) and Ruby Hashes and comes with some additional helpers
# for working with SOAP services.
class ApricotEatsGorilla
class << self
+ # SOAP namespaces by SOAP version.
+ SOAPNamespace = {
+ 1 => "http://schemas.xmlsoap.org/soap/envelope/",
+ 2 => "http://www.w3.org/2003/05/soap-envelope"
+ }
+
# Flag to enable sorting of Hash keys.
attr_accessor :sort_keys
# Flag to disable conversion of XML tags to lowerCamelCase.
attr_accessor :disable_tag_names_to_lower_camel_case
@@ -105,11 +111,12 @@
nested_data_to_xml(hash.keys.first, hash.values.first)
end
# Builds a SOAP request envelope and includes the content of a given
# +block+ into the envelope body. Accepts a Hash of additional +namespaces+
- # to set.
+ # to set. Also accepts an optional +version+ to specify the SOAP envelope
+ # namespace to use by SOAP version.
#
# ==== Examples
#
# ApricotEatsGorilla.soap_envelope do
# "<apricot><eats>Gorilla</eats></apricot>"
@@ -126,11 +133,12 @@
# # => '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://example.com">
# # => <env:Body>
# # => pureText
# # => </env:Body>
# # => </env:Envelope>'
- def soap_envelope(namespaces = {})
- namespaces[:env] = "http://schemas.xmlsoap.org/soap/envelope/"
+ def soap_envelope(namespaces = {}, version = 1)
+ namespaces[:env] = SOAPNamespace[version] unless
+ namespaces[:env] || SOAPNamespace[version].nil?
xml_node("env:Envelope", namespaces) do
xml_node("env:Body") { yield if block_given? }
end
end