class GoogleAdsSavon::SOAP::RequestBuilder
GoogleAdsSavon::SOAP::RequestBuilder
¶ ↑
GoogleAdsSavon::SOAP::RequestBuilder
builds GoogleAdsSavon::SOAP::Request
instances. The RequestBuilder
is configured by the client that instantiates it. It uses the options set by the client to build an appropriate request.
Attributes
Writer for the attributes of the SOAP
input tag. Accepts a Hash.
Writer for the GoogleAdsSavon::Config
object.
Writer for the HTTPI::Request
object.
Writer for the namespace identifer of the GoogleAdsSavon::SOAP::XML
object.
Reader for the operation of the request being built by the request builder.
Writer for the GoogleAdsSavon::SOAP::XML
object.
Writer for the SOAP
action of the GoogleAdsSavon::SOAP::XML
object.
Writer for the Wasabi::Document
object.
Writer for the Akami::WSSE
object.
Public Class Methods
Initialize a new RequestBuilder
with the given SOAP
operation. The operation may be specified using a symbol or a string.
# File lib/ads_savon/soap/request_builder.rb, line 13 def initialize(operation, options = {}) @operation = operation assign_options(options) end
Public Instance Methods
Returns the attributes of the SOAP
input tag. Defaults to an empty Hash.
# File lib/ads_savon/soap/request_builder.rb, line 137 def attributes @attributes ||= {} end
Returns the body of the SOAP
request.
# File lib/ads_savon/soap/request_builder.rb, line 131 def body soap.body end
Changes the body of the SOAP
request to body
.
# File lib/ads_savon/soap/request_builder.rb, line 126 def body=(body) soap.body = body end
Returns the GoogleAdsSavon::Config
object for the request. Defaults to a clone of GoogleAdsSavon.config
.
# File lib/ads_savon/soap/request_builder.rb, line 143 def config @config ||= GoogleAdsSavon.config.clone end
Returns the HTTPI::Request
object.
# File lib/ads_savon/soap/request_builder.rb, line 148 def http @http ||= HTTPI::Request.new end
Returns the namespace identifier to be used for the the SOAP
input tag. If +@namespace_identifier+ is not nil
, it will be returned. Otherwise, the default namespace identifier as returned by namespace_identifier
will be returned.
# File lib/ads_savon/soap/request_builder.rb, line 78 def input_namespace_identifier @namespace_identifier || namespace_identifier end
Returns the default namespace to be used for the SOAP
request. If a namespace is defined for the operation in the WSDL document, this namespace will be returned. Otherwise, the default WSDL document namespace will be returned.
# File lib/ads_savon/soap/request_builder.rb, line 85 def namespace if operation_namespace_defined_in_wsdl? wsdl.parser.namespaces[namespace_identifier.to_s] else wsdl.namespace end end
Returns the identifier for the default namespace. If an operation namespace identifier is defined for the current operation in the WSDL document, this namespace identifier is used. Otherwise, the +@namespace_identifier+ instance variable is used.
# File lib/ads_savon/soap/request_builder.rb, line 66 def namespace_identifier if operation_namespace_defined_in_wsdl? wsdl.operations[operation][:namespace_identifier].to_sym else @namespace_identifier end end
Returns true if the operation's namespace is defined within the WSDL document.
# File lib/ads_savon/soap/request_builder.rb, line 95 def operation_namespace_defined_in_wsdl? return false unless wsdl.document? (operation = wsdl.operations[self.operation]) && operation[:namespace_identifier] end
Builds and returns a GoogleAdsSavon::SOAP::Request
object. You may optionally pass a block to the method that will be run after the initial configuration of the dependencies. self
will be yielded to the block if the block accepts an argument.
# File lib/ads_savon/soap/request_builder.rb, line 50 def request(&post_configuration_block) configure_dependencies if post_configuration_block # Only yield self to the block if our block takes an argument args = [] and (args << self if post_configuration_block.arity == 1) post_configuration_block.call(*args) end Request.new(config, http, soap) end
Returns the SOAP::XML
object.
# File lib/ads_savon/soap/request_builder.rb, line 153 def soap @soap ||= XML.new(config) end
Returns the SOAP
action. If +@soap_action+ has been defined, this will be returned. Otherwise, if there is a WSDL document defined, the SOAP
action corresponding to the operation will be returned. Failing this, the operation name will be used to form the SOAP
action.
# File lib/ads_savon/soap/request_builder.rb, line 104 def soap_action return @soap_action if @soap_action if wsdl.document? wsdl.soap_action(operation.to_sym) else Gyoku::XMLKey.create(operation).to_sym end end
Returns the SOAP
operation input tag. If there is a WSDL document defined, and the operation's input tag is defined in the document, this will be returned. Otherwise, the operation name will be used to form the input tag.
# File lib/ads_savon/soap/request_builder.rb, line 117 def soap_input_tag if wsdl.document? && (input = wsdl.soap_input(operation.to_sym)) input else Gyoku::XMLKey.create(operation) end end
Returns the Wasabi::Document
object.
# File lib/ads_savon/soap/request_builder.rb, line 158 def wsdl @wsdl ||= Wasabi::Document.new end
Returns the Akami::WSSE
object.
# File lib/ads_savon/soap/request_builder.rb, line 163 def wsse @wsse ||= Akami.wsse end
Private Instance Methods
# File lib/ads_savon/soap/request_builder.rb, line 185 def add_wsdl_namespaces_to_soap wsdl.type_namespaces.each do |path, uri| soap.use_namespace(path, uri) end end
# File lib/ads_savon/soap/request_builder.rb, line 191 def add_wsdl_types_to_soap wsdl.type_definitions.each do |path, type| soap.types[path] = type end end
# File lib/ads_savon/soap/request_builder.rb, line 197 def assign_options(options) options.each do |option, value| send(:"#{option}=", value) if value end end
# File lib/ads_savon/soap/request_builder.rb, line 169 def configure_dependencies soap.endpoint = wsdl.endpoint soap.element_form_default = wsdl.element_form_default soap.wsse = wsse soap.namespace = namespace soap.namespace_identifier = namespace_identifier add_wsdl_namespaces_to_soap add_wsdl_types_to_soap soap.input = [input_namespace_identifier, soap_input_tag.to_sym, attributes] http.headers["SOAPAction"] = %{"#{soap_action}"} end