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 Method Summary collapse

Constructor Details

#initialize(provided_config = nil) ⇒ Api

Constructor for API.



40
41
42
43
# File 'lib/adwords_api.rb', line 40

def initialize(provided_config = nil)
  super(provided_config)
  @credential_handler = AdwordsApi::CredentialHandler.new(@config)
end

Instance Method Details

#api_configObject

Getter for the API service configurations



46
47
48
# File 'lib/adwords_api.rb', line 46

def api_config()
  AdwordsApi::ApiConfig
end

#include_zero_impressions=(value) ⇒ Object

Helper method to include zero impressions when downloading reports.

Args:

  • value: whether to include zero impressions (boolean)



136
137
138
# File 'lib/adwords_api.rb', line 136

def include_zero_impressions=(value)
  @config.set('library.include_zero_impressions_header', value)
end

#partial_failure(&block) ⇒ Object

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:

  • block execution result, if block given

  • boolean indicating whether partial failure operations are currently

enabled or disabled, if no block provided



152
153
154
155
156
# File 'lib/adwords_api.rb', line 152

def partial_failure(&block)
  return (block_given?) ?
    run_with_temporary_flag(:@partial_failure, true, block) :
    @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)



164
165
166
# File 'lib/adwords_api.rb', line 164

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

#report_utils(version = nil) ⇒ Object

Returns an instance of ReportUtils object with all utilities relevant to the reporting.

Args:

  • version: version of the API to use (optional).



174
175
176
177
178
179
180
181
# File 'lib/adwords_api.rb', line 174

def report_utils(version = nil)
  version = api_config.default_version if version.nil?
  # Check if version exists.
  if !api_config.versions.include?(version)
    raise AdsCommon::Errors::Error, "Unknown version '%s'" % version
  end
  return AdwordsApi::ReportUtils.new(self, version)
end

#skip_column_header=(value) ⇒ Object

Helper method to skip the column header when downloading reports.

Args:

  • value: whether to skip the column header (boolean)



127
128
129
# File 'lib/adwords_api.rb', line 127

def skip_column_header=(value)
  @config.set('library.skip_column_header', value)
end

#skip_report_header=(value) ⇒ Object

Helper method to skip the report header when downloading reports.

Args:

  • value: whether to skip the report header (boolean)



109
110
111
# File 'lib/adwords_api.rb', line 109

def skip_report_header=(value)
  @config.set('library.skip_report_header', value)
end

#skip_report_summary=(value) ⇒ Object

Helper method to skip the report summary when downloading reports.

Args:

  • value: whether to skip the report summary (boolean)



118
119
120
# File 'lib/adwords_api.rb', line 118

def skip_report_summary=(value)
  @config.set('library.skip_report_summary', value)
end

#soap_header_handler(auth_handler, version, header_ns, default_ns) ⇒ Object

Retrieve correct soap_header_handler.

Args:

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

  • version: intended API version

  • header_ns: header namespace

  • default_ns: default namespace

Returns:

  • SOAP header handler



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/adwords_api.rb', line 62

def soap_header_handler(auth_handler, version, header_ns, default_ns)
  auth_method = @config.read('authentication.method', :OAUTH2)
  handler_class = case auth_method
    when :OAUTH2, :OAUTH2_SERVICE_ACCOUNT
      AdsCommon::SavonHeaders::OAuthHeaderHandler
    else
      raise AdsCommon::Errors::AuthError,
          "Unknown auth method: %s" % auth_method
    end
  return handler_class.new(@credential_handler, auth_handler, header_ns,
                              default_ns, version)
end

#validate_only(&block) ⇒ Object

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:

  • block execution result, if block given

  • boolean indicating whether validate-only operations are currently enabled or disabled, if no block provided



87
88
89
90
91
# File 'lib/adwords_api.rb', line 87

def validate_only(&block)
  return (block_given?) ?
    run_with_temporary_flag(:@validate_only, true, block) :
    @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)



100
101
102
# File 'lib/adwords_api.rb', line 100

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