Class: GoogleAdsSavon::SOAP::RequestBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ads_savon/soap/request_builder.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation, options = {}) ⇒ RequestBuilder

Initialize a new RequestBuilder with the given SOAP operation. The operation may be specified using a symbol or a string.



13
14
15
16
# File 'lib/ads_savon/soap/request_builder.rb', line 13

def initialize(operation, options = {})
  @operation = operation
  assign_options(options)
end

Instance Attribute Details

#attributesObject

Returns the attributes of the SOAP input tag. Defaults to an empty Hash.



137
138
139
# File 'lib/ads_savon/soap/request_builder.rb', line 137

def attributes
  @attributes ||= {}
end

#configObject

Returns the GoogleAdsSavon::Config object for the request. Defaults to a clone of GoogleAdsSavon.config.



143
144
145
# File 'lib/ads_savon/soap/request_builder.rb', line 143

def config
  @config ||= GoogleAdsSavon.config.clone
end

#httpObject

Returns the HTTPI::Request object.



148
149
150
# File 'lib/ads_savon/soap/request_builder.rb', line 148

def http
  @http ||= HTTPI::Request.new
end

#namespace_identifierObject

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.



66
67
68
69
70
71
72
# 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

#operationObject (readonly)

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



44
45
46
# File 'lib/ads_savon/soap/request_builder.rb', line 44

def operation
  @operation
end

#soapObject

Returns the SOAP::XML object.



153
154
155
# File 'lib/ads_savon/soap/request_builder.rb', line 153

def soap
  @soap ||= XML.new(config)
end

#soap_actionObject

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.



104
105
106
107
108
109
110
111
112
# 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

#wsdlObject

Returns the Wasabi::Document object.



158
159
160
# File 'lib/ads_savon/soap/request_builder.rb', line 158

def wsdl
  @wsdl ||= Wasabi::Document.new
end

#wsseObject

Returns the Akami::WSSE object.



163
164
165
# File 'lib/ads_savon/soap/request_builder.rb', line 163

def wsse
  @wsse ||= Akami.wsse
end

Instance Method Details

#bodyObject

Returns the body of the SOAP request.



131
132
133
# File 'lib/ads_savon/soap/request_builder.rb', line 131

def body
  soap.body
end

#body=(body) ⇒ Object

Changes the body of the SOAP request to body.



126
127
128
# File 'lib/ads_savon/soap/request_builder.rb', line 126

def body=(body)
  soap.body = body
end

#input_namespace_identifierObject

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.



78
79
80
# File 'lib/ads_savon/soap/request_builder.rb', line 78

def input_namespace_identifier
  @namespace_identifier || namespace_identifier
end

#namespaceObject

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.



85
86
87
88
89
90
91
# 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

#operation_namespace_defined_in_wsdl?Boolean

Returns true if the operation’s namespace is defined within the WSDL document.

Returns:

  • (Boolean)


95
96
97
98
# 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) ⇒ Object

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.



50
51
52
53
54
55
56
57
58
59
60
# 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_input_tagObject

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.



117
118
119
120
121
122
123
# 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