Class: BingAdsApi::Api

Inherits:
AdsCommonForBingAds::Api show all
Defined in:
lib/bing_ads_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.



26
27
28
29
# File 'lib/bing_ads_api.rb', line 26

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

Instance Method Details

#api_configObject

Getter for the API service configurations



32
33
34
# File 'lib/bing_ads_api.rb', line 32

def api_config()
  BingAdsApi::ApiConfig
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



127
128
129
130
131
# File 'lib/bing_ads_api.rb', line 127

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)



139
140
141
# File 'lib/bing_ads_api.rb', line 139

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).



149
150
151
152
153
154
155
156
# File 'lib/bing_ads_api.rb', line 149

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

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

Retrieve correct soap_header_handler.

Args:

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

  • version: intended API version

  • header_ns: header namespace

  • default_ns: default namespace

Returns:

  • SOAP header handler



48
49
50
51
52
53
54
55
# File 'lib/bing_ads_api.rb', line 48

def soap_header_handler(auth_handler, version, header_ns, default_ns)
  auth_method = @config.read('authentication.method', :CLIENTLOGIN)
  handler_class = case auth_method
                  when :CLIENTLOGIN then BingAdsApi::ClientLoginHeaderHandler
                  when :OAUTH, :OAUTH2 then AdsCommonForBingAds::SavonHeaders::OAuthHeaderHandler
                  end
  return handler_class.new(@credential_handler, auth_handler, header_ns, default_ns, version)
end

#use_mcc(&block) ⇒ Object

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:

  • block execution result, if block given

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



69
70
71
72
73
# File 'lib/bing_ads_api.rb', line 69

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



82
83
84
# File 'lib/bing_ads_api.rb', line 82

def use_mcc=(value)
  @credential_handler.use_mcc = value
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



98
99
100
101
102
# File 'lib/bing_ads_api.rb', line 98

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)



111
112
113
# File 'lib/bing_ads_api.rb', line 111

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