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

attributes[W]

Writer for the attributes of the SOAP input tag. Accepts a Hash.

config[W]

Writer for the GoogleAdsSavon::Config object.

http[W]

Writer for the HTTPI::Request object.

namespace_identifier[W]

Writer for the namespace identifer of the GoogleAdsSavon::SOAP::XML object.

operation[R]

Reader for the operation of the request being built by the request builder.

soap[W]

Writer for the GoogleAdsSavon::SOAP::XML object.

soap_action[W]

Writer for the SOAP action of the GoogleAdsSavon::SOAP::XML object.

wsdl[W]

Writer for the Wasabi::Document object.

wsse[W]

Writer for the Akami::WSSE object.

Public Class Methods

new(operation, options = {}) click to toggle source

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

attributes() click to toggle source

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

Returns the body of the SOAP request.

# File lib/ads_savon/soap/request_builder.rb, line 131
def body
  soap.body
end
body=(body) click to toggle source

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

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

Returns the HTTPI::Request object.

# File lib/ads_savon/soap/request_builder.rb, line 148
def http
  @http ||= HTTPI::Request.new
end
input_namespace_identifier() click to toggle source

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

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

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

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
request(&post_configuration_block) click to toggle source

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

Returns the SOAP::XML object.

# File lib/ads_savon/soap/request_builder.rb, line 153
def soap
  @soap ||= XML.new(config)
end
soap_action() click to toggle source

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

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

Returns the Wasabi::Document object.

# File lib/ads_savon/soap/request_builder.rb, line 158
def wsdl
  @wsdl ||= Wasabi::Document.new
end
wsse() click to toggle source

Returns the Akami::WSSE object.

# File lib/ads_savon/soap/request_builder.rb, line 163
def wsse
  @wsse ||= Akami.wsse
end

Private Instance Methods

add_wsdl_namespaces_to_soap() click to toggle source
# 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
add_wsdl_types_to_soap() click to toggle source
# 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
assign_options(options) click to toggle source
# 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
configure_dependencies() click to toggle source
# 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