Contains helper methods for loading and managing the available services.

Methods
A
D
E
G
V
Constants
DEFAULT_VERSION = 201008
 

Set defaults

DEFAULT_ENVIRONMENT = 'PRODUCTION'
Class Public methods
add_environment(name, endpoint_hash)

Add a new environment to the list.

Args:

  • name: the name for the new environment
  • endpoint_hash: a hash of base endpoint URLs, indexed by version number, e.g.:
     { 13 => 'URL_FOR_v13', 200906 => 'URL_FOR_v200906' }
    
# File lib/adwords4r/services.rb, line 296
    def self.add_environment(name, endpoint_hash)
      @@environments[name] = endpoint_hash
    end
do_require(version)

Perform the loading of the necessary source files for a version

Args:

  • version: the API version (as an integer)
# File lib/adwords4r/services.rb, line 305
    def self.do_require(version)
      get_services(version).each do |service|
        eval("require 'adwords4r/v#{version}/#{service}ServiceWrapper.rb'")
      end
    end
environment_has_version(environment, version)

Does the given environment exist and contain the given version?

Returns: Boolean indicating whether the given environment exists and contains the given version

# File lib/adwords4r/services.rb, line 166
    def self.environment_has_version(environment, version)
      return (!@@environments[environment].nil? and
              !@@environments[environment][version].nil?)
    end
get_auth_server(environment)

Get the authentication server details for an environment

Args:

  • environment: the service environment to be used (as a string)

Returns: Array containing

  • the hostname for the auth server (as a string)
  • the port for the auth server (as an integer)
  • whether to use SSL or not (as a boolean)
# File lib/adwords4r/services.rb, line 278
    def self.get_auth_server(environment)
      # If we don't have an entry for this environment, we just return the
      # default server (the same one being used for the default environment)
      if @@auth_servers[environment].nil?
        return @@auth_servers[DEFAULT_ENVIRONMENT]
      end

      return @@auth_servers[environment]
    end
get_default_environment()

Get the default environment.

Returns: Default environment (as a string)

# File lib/adwords4r/services.rb, line 217
    def self.get_default_environment
      return DEFAULT_ENVIRONMENT
    end
get_default_version()

Get the default API version.

Returns: Default version (as an integer)

# File lib/adwords4r/services.rb, line 187
    def self.get_default_version
      return DEFAULT_VERSION
    end
get_endpoint(environment, version, service)

Get the endpoint for a service on a given environment and API version.

Args:

  • environment: the service environment to be used (as a string)
  • version: the API version (as an integer)
  • service: the name of the API service (as a string)

Returns: The endpoint URL (as a string)

# File lib/adwords4r/services.rb, line 231
    def self.get_endpoint(environment, version, service)
      base = @@environments[environment][version]
      path = @@subdirs[[version, service]]
      return base.to_s + path.to_s if base
      return nil
    end
get_environments()

Get the available environments.

Returns: List of available environments (as strings)

# File lib/adwords4r/services.rb, line 208
    def self.get_environments
      @@environments.keys
    end
get_interface_name(version, service)

Returns the full interface class name for a given service

Args:

  • version: the API version (as an integer)
  • service: the service name (as a string)

Returns: The full interface class name for the given service (as a string)

# File lib/adwords4r/services.rb, line 333
    def self.get_interface_name(version, service)
      if version.is_a? Integer and version <= 13
        return get_module_name(version, service) + "::#{service}Interface"
      else
        return get_module_name(version, service) +
            "::#{service}ServiceInterface"
      end
    end
get_latest_version()

Get the latest API version.

Returns: Latest version (as an integer)

# File lib/adwords4r/services.rb, line 156
    def self.get_latest_version
      @@services.keys.select { |service| service.is_a? Integer }.max
    end
get_module_name(version, service)

Returns the full module name for a given service

Args:

  • version: the API version (as an integer)
  • service: the service name (as a string)

Returns: The full module name for the given service (as a string)

# File lib/adwords4r/services.rb, line 320
    def self.get_module_name(version, service)
      return "AdWords::V#{version.to_s}::#{service}Service"
    end
get_namespace_v2009(driver)

Returns the namespace for a version and service

Args:

  • driver: the service driver

Returns: String with the namespace

# File lib/adwords4r/services.rb, line 362
    def self.get_namespace_v2009(driver)
      # This is a huge hack to get the correct namespace for a given service,
      # but short from configuring it ourselves there seems to be no other
      # option. This accesses one of the fields in the description of the
      # service's methods, which indicates the namespace.
      # Thankfully, since it's a constant and checked as part of our unit tests,
      # it should always work.
      return driver.class::Methods[0][2][0][2][1]
    end
get_report_download_url(environment, version)

Get the download URL for reports.

Args:

  • environment: the service environment to be used (as a string)
  • version: the API version (as an integer)

Returns: The endpoint URL (as a string)

# File lib/adwords4r/services.rb, line 247
    def self.get_report_download_url(environment, version)
      base = @@environments[environment][version]
      path = 'reportdownload' if version >= 201003
      return base.to_s + path.to_s if base and path
      return nil
    end
get_services(version)

Get the list of service names for a given version

Args:

  • version: the API version (as an integer)

Returns: List of names of services (as strings) available for given version

# File lib/adwords4r/services.rb, line 199
    def self.get_services(version)
      @@services[version]
    end
get_subdir(version, service)

Get the subdirectory for a service, for a given API version.

Args:

  • version: the API version (as an integer)
  • service: the name of the API service (as a string)

Returns: The endpoint URL (as a string)

# File lib/adwords4r/services.rb, line 263
    def self.get_subdir(version, service)
      return @@subdirs[[version, service]]
    end
get_versions()

Get the available API versions.

Returns: List of versions available (as integers)

# File lib/adwords4r/services.rb, line 147
    def self.get_versions
      @@services.keys
    end
get_wrapper_name(version, service)

Returns the full wrapper class name for a given service

Args:

  • version: the API version (as an integer)
  • service: the service name (as a string)

Returns: The full wrapper class name for the given service (as a string)

# File lib/adwords4r/services.rb, line 351
    def self.get_wrapper_name(version, service)
      return get_module_name(version, service) + "::#{service}ServiceWrapper"
    end
validate_param(param_name, param, type)

Validates whether a parameter is of the correct type This method is invoked by the wrappers during runtime to check the validity of every parameter.

Args:

  • param_name: the parameter name (as a String)
  • param: the parameter value
  • type: the expected type (the class object itself)

Returns: nil, upon success

Raises:

  • ArgumentError: in case of an unexpected type
# File lib/adwords4r/services.rb, line 387
    def self.validate_param(param_name, param, type)
      return nil if param.is_a? type

      begin
        type.new(param)
      rescue
        raise ArgumentError, "Parameter '#{param_name}'" +
            " should be convertible into type #{type.to_s}"
      end
      return nil
    end
version_has_service(version, service)

Does the given version exist and contain the given service?

Returns: Boolean indicating whether the given version exists and contains the given service

# File lib/adwords4r/services.rb, line 177
    def self.version_has_service(version, service)
      return (!@@services[version].nil? and
              @@services[version].include?(service))
    end