Class: AdwordsApi::Api

Inherits:
AdsCommon::Api
  • Object
show all
Defined in:
lib/adwords_api.rb

Overview

Wrapper class that serves as the main point of access for all the API usage.

Holds all the services, as well as login credentials.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provided_config = nil) ⇒ Api

Constructor for Api.



107
108
109
110
111
112
113
114
# File 'lib/adwords_api.rb', line 107

def initialize(provided_config = nil)
  super(provided_config)
  @credential_handler = AdwordsApi::CredentialHandler.new(@config)
  @drivers = Hash.new
  @total_units = 0
  @last_units = 0
  @mutex = Mutex.new
end

Instance Attribute Details

#client_login_handlerObject

Accessor for client login handler, so that we can access the token.



59
60
61
# File 'lib/adwords_api.rb', line 59

def 
  @client_login_handler
end

#last_unitsObject

Number of units spent on the last operation via this API object



54
55
56
# File 'lib/adwords_api.rb', line 54

def last_units
  @last_units
end

#mutexObject (readonly)

Mutex object for controlling concurrent access to API object data



52
53
54
# File 'lib/adwords_api.rb', line 52

def mutex
  @mutex
end

#total_unitsObject

Number of units spent in total, via this API object



56
57
58
# File 'lib/adwords_api.rb', line 56

def total_units
  @total_units
end

Instance Method Details

#api_configObject

Getter for the API service configurations



64
65
66
# File 'lib/adwords_api.rb', line 64

def api_config
  AdwordsApi::ApiConfig
end

#create_callback_handlerObject

Auxiliary method to create a new Soap4rResponseHandler, of the type we want to use for AdWords logging



70
71
72
# File 'lib/adwords_api.rb', line 70

def create_callback_handler
  AdwordsApi::Soap4rResponseHandler.new(self)
end

#partial_failureObject

Helper method to provide a simple way of performing requests with support for partial failures. Executes a block of code with partial failures enabled and/or returns the current status of the property.

Args:

  • accepts a block, which it will execute as a partial failure operation.

Returns: Boolean indicating whether partial failure operations are currently enabled or disabled



197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/adwords_api.rb', line 197

def partial_failure
  if block_given?
    previous = @credential_handler.partial_failure
    begin
      @credential_handler.partial_failure = true
      yield
    ensure
      @credential_handler.partial_failure = previous
    end
  end
  return @credential_handler.partial_failure
end

#partial_failure=(value) ⇒ Object

Helper method to provide a simple way of performing requests with support for partial failures.

Args:

  • value: the new value for the property (boolean)



216
217
218
# File 'lib/adwords_api.rb', line 216

def partial_failure=(value)
  @credential_handler.partial_failure = value
end

#soap_header_handlers(auth_handler, header_list, version, wrapper) ⇒ Object

Retrieve single NestedHeaderHandler for v20xx and one SingleHeaderHandler per credential for v13.

Args:

  • auth_handler: instance of an AdsCommon::Auth::BaseHandler subclass to handle authentication

  • header_list: the list of headers to be handled

  • version: intended API version

  • wrapper: wrapper object for the service being handled

Returns:

  • a list of SOAP header handlers; one per provided header



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/adwords_api.rb', line 87

def soap_header_handlers(auth_handler, header_list, version, wrapper)
  if version == :v13
    header_handlers = []
    header_list.each do |header|
      header_handlers << AdsCommon::Soap4rHeaders::SingleHeaderHandler.new(
          @credential_handler, auth_handler, header, nil, version)
    end
    return header_handlers
  else
    ns =
        api_config.headers_config[:HEADER_NAMESPACE_PREAMBLE] + version.to_s
    top_ns = wrapper.namespace
    return [AdsCommon::Soap4rHeaders::NestedHeaderHandler.new(
        @credential_handler, auth_handler,
        api_config.headers_config[:REQUEST_HEADER],
        top_ns, ns, version)]
  end
end

#use_mccObject

Helper method to provide a simple way of doing an MCC-level operation without the need to change credentials. Executes a block of code as an MCC-level operation and/or returns the current status of the property.

Args:

  • accepts a block, which it will execute as an MCC-level operation.

Returns: Boolean indicating whether MCC-level operations are currently enabled or disabled



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/adwords_api.rb', line 127

def use_mcc
  if block_given?
    previous = @credential_handler.use_mcc
    begin
      @credential_handler.use_mcc = true
      yield
    ensure
      @credential_handler.use_mcc = previous
    end
  end
  return @credential_handler.use_mcc
end

#use_mcc=(value) ⇒ Object

Helper method to provide a simple way of doing an MCC-level operation without the need to change credentials. Sets the value of the property that controls whether MCC-level operations are enabled or disabled.

Args:

  • value: the new value for the property (boolean)



147
148
149
# File 'lib/adwords_api.rb', line 147

def use_mcc=(value)
  @credential_handler.use_mcc = value
end

#validate_onlyObject

Helper method to provide a simple way of doing a validate-only operation without the need to change credentials. Executes a block of code as an validate-only operation and/or returns the current status of the property.

Args:

  • accepts a block, which it will execute as a validate-only operation.

Returns: Boolean indicating whether validate-only operations are currently enabled or disabled



162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/adwords_api.rb', line 162

def validate_only
  if block_given?
    previous = @credential_handler.validate_only
    begin
      @credential_handler.validate_only = true
      yield
    ensure
      @credential_handler.validate_only = previous
    end
  end
  return @credential_handler.validate_only
end

#validate_only=(value) ⇒ Object

Helper method to provide a simple way of performing validate-only operations. Sets the value of the property that controls whether validate-only operations are enabled or disabled.

Args:

  • value: the new value for the property (boolean)



182
183
184
# File 'lib/adwords_api.rb', line 182

def validate_only=(value)
  @credential_handler.validate_only = value
end