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

Holds all the services, as well as login credentials.

Methods
G
N
S
U
V
Attributes
[R] credentials

AdWordsCredentials object used for authentication

[R] xml_logger

AdWordsLogger object used for logging SOAP XML

[R] unit_logger

AdWordsLogger object used for logging request info

[R] mutex

Mutex object for controlling concurrent access to API object data

[RW] last_units

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

[RW] total_units

Number of units spent in total, via this API object

Class Public methods
new(credentials = AdWordsCredentials.new)

Constructor for API.

Args:

# File lib/adwords4r.rb, line 69
    def initialize(credentials = AdWordsCredentials.new)
      @credentials = credentials
      if !AdWords::Service.environments.include? @credentials.environment
        raise AdWords::Error::Error,
            "Unknown environment #{@credentials.environment}"
      end
      @drivers = Hash.new
      @wrappers = Hash.new
      @total_units = 0
      @last_units = 0
      log_to_console = !ENV['ADWORDS4R_DEBUG'].nil? &&
          ENV['ADWORDS4R_DEBUG'].upcase == 'TRUE'
      @xml_logger = AdWordsLogger.new('soap_xml', log_to_console)
      @unit_logger = AdWordsLogger.new('request_info')
      @mutex = Mutex.new
      prepare_drivers
    end
Instance Public methods
get_service(name, version = nil)

Obtain an API service, given a version and its name.

Args:

  • name: name for the intended service
  • version: intended API version. Must be an integer.

Returns:

  • the service wrapper for the intended service.
This method is also aliased as service
# File lib/adwords4r.rb, line 166
    def get_service(name, version = nil)
      if name.is_a? Integer and version.is_a? String
        name, version = version, name
        warn("This parameter order is deprecated. " +
             "Please use get_service(name, version) from now on.")
      elsif name.is_a? String
        # Do nothing
      else
        raise ArgumentError, "Wrong arguments. " +
            "Expected: get_service(name, version = nil)"
      end
      version = AdWords::Service::get_default_version if version == nil
      # Check if version exists
      if !AdWords::Service.get_versions.include?(version)
        if version.is_a? String
          raise AdWords::Error::Error, "Unknown version '#{version}'. Please " +
              "note that version numbers should be numeric, not strings"
        else
          raise AdWords::Error::Error, "Unknown version #{version}"
        end
      end
      # Check if the current environment supports the requested version
      if !AdWords::Service.environment_has_version(@credentials.environment,
          version)
        raise AdWords::Error::Error, "Environment #{@credentials.environment}" +
            " does not support version #{version}"
      end
      # Check if the specified version has the requested service
      if !AdWords::Service.version_has_service(version, name)
        raise AdWords::Error::Error, "Version #{version} does not contain " +
          "service #{name}"
      end
      return @wrappers[[version, name]]
    end
service(name, version = nil)

Alias for get_service

use_mcc()

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

# File lib/adwords4r.rb, line 98
    def use_mcc
      if block_given?
        previous = @credentials.use_mcc
        begin
          @credentials.use_mcc = true
          yield
        ensure
          @credentials.use_mcc = previous
        end
      end
      return @credentials.use_mcc
    end
use_mcc=(value)

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)
# File lib/adwords4r.rb, line 118
    def use_mcc=(value)
      @credentials.use_mcc = value
    end
validate_only()

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

# File lib/adwords4r.rb, line 133
    def validate_only
      if block_given?
        previous = @credentials.validate_only
        begin
          @credentials.validate_only = true
          yield
        ensure
          @credentials.validate_only = previous
        end
      end
      return @credentials.validate_only
    end
validate_only=(value)

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)
# File lib/adwords4r.rb, line 153
    def validate_only=(value)
      @credentials.validate_only = value
    end