Class: GoogleAdsSavon::SOAP::XML
- Inherits:
-
Object
- Object
- GoogleAdsSavon::SOAP::XML
- Defined in:
- lib/ads_savon/soap/xml.rb
Overview
GoogleAdsSavon::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
- SCHEMA_TYPES =
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
-
#body ⇒ Object
Accepts a
block
and yields aBuilder::XmlMarkup
object to let you create custom body XML. -
#config ⇒ Object
Returns the value of attribute config.
-
#element_form_default ⇒ Object
Accessor for whether all local elements should be namespaced.
-
#encoding ⇒ Object
Returns the SOAP request encoding.
-
#endpoint ⇒ Object
Accessor for the SOAP
endpoint
. -
#env_namespace ⇒ Object
Returns the SOAP envelope namespace.
-
#header ⇒ Object
Returns the SOAP
header
. -
#input ⇒ Object
Accessor for the SOAP
input
tag. -
#namespace ⇒ Object
Accessor for the default namespace URI.
-
#namespace_identifier ⇒ Object
Returns the default namespace identifier.
-
#namespaces ⇒ Object
Returns the
namespaces
. -
#wsse ⇒ Object
Accessor for the
GoogleAdsSavon::WSSE
object. -
#xml(directive_tag = :xml, attrs = {}) ⇒ Object
Accepts a
block
and yields aBuilder::XmlMarkup
object to let you create a completely custom XML.
Instance Method Summary collapse
-
#initialize(config) ⇒ XML
constructor
Expects a
config
object. - #namespace_by_uri(uri) ⇒ Object
- #signature? ⇒ Boolean
-
#to_xml(clear_cache = false) ⇒ Object
Returns the XML for a SOAP request.
- #types ⇒ Object
- #use_namespace(path, uri) ⇒ Object
- #used_namespaces ⇒ Object
-
#version ⇒ Object
Returns the SOAP
version
. -
#version=(version) ⇒ Object
Sets the SOAP
version
.
Constructor Details
#initialize(config) ⇒ XML
Expects a config
object.
24 25 26 |
# File 'lib/ads_savon/soap/xml.rb', line 24 def initialize(config) self.config = config end |
Instance Attribute Details
#body ⇒ Object
Accepts a block
and yields a Builder::XmlMarkup
object to let you create custom body XML.
133 134 135 136 |
# File 'lib/ads_savon/soap/xml.rb', line 133 def body @body = yield builder(nil) if block_given? @body end |
#config ⇒ Object
Returns the value of attribute config.
28 29 30 |
# File 'lib/ads_savon/soap/xml.rb', line 28 def config @config end |
#element_form_default ⇒ Object
Accessor for whether all local elements should be namespaced.
111 112 113 |
# File 'lib/ads_savon/soap/xml.rb', line 111 def element_form_default @element_form_default end |
#encoding ⇒ Object
Returns the SOAP request encoding. Defaults to “UTF-8”.
124 125 126 |
# File 'lib/ads_savon/soap/xml.rb', line 124 def encoding @encoding ||= "UTF-8" end |
#endpoint ⇒ Object
Accessor for the SOAP endpoint
.
34 35 36 |
# File 'lib/ads_savon/soap/xml.rb', line 34 def endpoint @endpoint end |
#env_namespace ⇒ Object
Returns the SOAP envelope namespace. Uses the global namespace if set Defaults to :env.
59 60 61 |
# File 'lib/ads_savon/soap/xml.rb', line 59 def env_namespace @env_namespace ||= config.env_namespace.nil? ? :env : config.env_namespace end |
#header ⇒ Object
Returns the SOAP header
. Defaults to an empty Hash.
51 52 53 |
# File 'lib/ads_savon/soap/xml.rb', line 51 def header @header ||= config.soap_header.nil? ? {} : config.soap_header end |
#input ⇒ Object
Accessor for the SOAP input
tag.
31 32 33 |
# File 'lib/ads_savon/soap/xml.rb', line 31 def input @input end |
#namespace ⇒ Object
Accessor for the default namespace URI.
114 115 116 |
# File 'lib/ads_savon/soap/xml.rb', line 114 def namespace @namespace end |
#namespace_identifier ⇒ Object
Returns the default namespace identifier.
106 107 108 |
# File 'lib/ads_savon/soap/xml.rb', line 106 def namespace_identifier @namespace_identifier ||= :wsdl end |
#namespaces ⇒ Object
Returns the namespaces
. Defaults to a Hash containing the SOAP envelope namespace.
67 68 69 70 71 72 73 |
# File 'lib/ads_savon/soap/xml.rb', line 67 def namespaces @namespaces ||= begin key = ["xmlns"] key << env_namespace if env_namespace && env_namespace != "" { key.join(":") => SOAP::NAMESPACE[version] } end end |
#wsse ⇒ Object
Accessor for the GoogleAdsSavon::WSSE
object.
117 118 119 |
# File 'lib/ads_savon/soap/xml.rb', line 117 def wsse @wsse end |
#xml(directive_tag = :xml, attrs = {}) ⇒ Object
Accepts a block
and yields a Builder::XmlMarkup
object to let you create a completely custom XML.
144 145 146 |
# File 'lib/ads_savon/soap/xml.rb', line 144 def xml(directive_tag = :xml, attrs = {}) @xml = yield builder(directive_tag, attrs) if block_given? end |
Instance Method Details
#namespace_by_uri(uri) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/ads_savon/soap/xml.rb', line 75 def namespace_by_uri(uri) namespaces.each do |candidate_identifier, candidate_uri| return candidate_identifier.gsub(/^xmlns:/, '') if candidate_uri == uri end nil end |
#signature? ⇒ Boolean
119 120 121 |
# File 'lib/ads_savon/soap/xml.rb', line 119 def signature? wsse.respond_to?(:signature?) && wsse.signature? end |
#to_xml(clear_cache = false) ⇒ Object
Returns the XML for a SOAP request.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/ads_savon/soap/xml.rb', line 152 def to_xml(clear_cache = false) if clear_cache @xml = nil @header_for_xml = nil end @xml ||= tag(builder, :Envelope, complete_namespaces) do |xml| tag(xml, :Header) { xml << header_for_xml } unless header_for_xml.empty? # TODO: Maybe there should be some sort of plugin architecture where # classes like WSSE::Signature can hook into this process. body_attributes = (signature? ? wsse.signature.body_attributes : {}) if input.nil? tag(xml, :Body, body_attributes) else tag(xml, :Body, body_attributes) { xml.tag!(*add_namespace_to_input) { xml << body_to_xml } } end end end |
#types ⇒ Object
98 99 100 |
# File 'lib/ads_savon/soap/xml.rb', line 98 def types @types ||= {} end |
#use_namespace(path, uri) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ads_savon/soap/xml.rb', line 86 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_namespaces ⇒ Object
82 83 84 |
# File 'lib/ads_savon/soap/xml.rb', line 82 def used_namespaces @used_namespaces ||= {} end |
#version ⇒ Object
Returns the SOAP version
. Defaults to GoogleAdsSavon.config.soap_version
.
43 44 45 |
# File 'lib/ads_savon/soap/xml.rb', line 43 def version @version ||= config.soap_version end |