module AdsCommon::ApiConfig

Contains helper methods for loading and managing the available services. This module is meant to be imported into API-specific modules.

Constants

CLIENT_LIB_VERSION

Public Instance Methods

api_name() click to toggle source

Get the API name.

# File lib/ads_common/api_config.rb, line 87
def api_name
  raise NotImplementedError, 'api_name not overriden.'
end
api_path() click to toggle source

Get the API path.

# File lib/ads_common/api_config.rb, line 92
def api_path
  return api_name.to_s.snakecase
end
default_config_filename() click to toggle source

Get the default filename for the config file.

# File lib/ads_common/api_config.rb, line 97
def default_config_filename
  raise NotImplementedError, 'default_config_filename not overriden.'
end
default_version() click to toggle source

Get the default API version.

Returns: Default version

# File lib/ads_common/api_config.rb, line 70
def default_version
  nil
end
do_require(version, service) click to toggle source

Perform the loading of the necessary source files for a version.

Args:

  • version: the API version

  • service: service name

Returns: The filename that was loaded

# File lib/ads_common/api_config.rb, line 141
def do_require(version, service)
  filename = [api_path, version.to_s, service.to_s.snakecase].join('/')
  require filename
  return filename
end
endpoint(version, service) click to toggle source

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

Args:

  • version: the API version

  • service: the name of the API service

Returns: The endpoint URL

# File lib/ads_common/api_config.rb, line 110
def endpoint(version, service)
  base = get_wsdl_base(version)
  if !subdir_config().nil?
    base = base.to_s + subdir_config()[[version, service]].to_s
  end
  return base.to_s + version.to_s + '/' + service.to_s
end
get_wsdl_base(version) click to toggle source

Returns WSDL base url defined in Service configuration. Allows to override the base URL via environmental variable.

Args:

- version: the API version

Returns:

String containing base URL
# File lib/ads_common/api_config.rb, line 208
def get_wsdl_base(version)
  return ENV['ADSAPI_BASE_URL'] || config(version)
end
get_wsdls(version) click to toggle source

Generates an array of WSDL URLs based on defined Services and version supplied. This method is used by generators to determine what service wrappers to generate.

Args:

- version: the API version.

Returns

hash of pairs Service => WSDL URL
# File lib/ads_common/api_config.rb, line 183
def get_wsdls(version)
  res = {}
  wsdl_base = get_wsdl_base(version)
  postfix = wsdl_base.start_with?('http') ? '?wsdl' : '.wsdl'
  services(version).each do |service|
    path = wsdl_base
    if (!subdir_config().nil?)
      subdir_name = subdir(version, service);
      path = path + subdir_name if subdir_name and !subdir_name.empty?
    end
    path = path + version.to_s + '/' + service.to_s + postfix
    res[service.to_s] = path
  end
  return res
end
has_version(version) click to toggle source

Does the current config contain the given version?

Returns: Boolean indicating whether the current config contains the given version

# File lib/ads_common/api_config.rb, line 50
def has_version(version)
  return !config(version).nil?
end
interface_name(version, service) click to toggle source

Returns the full interface class name for a given service.

Args:

  • version: the API version

  • service: the service name

Returns: The full interface class name for the given service

# File lib/ads_common/api_config.rb, line 169
def interface_name(version, service)
  return [module_name(version, service), service.to_s].join('::')
end
latest_version() click to toggle source

Get the latest API version.

Returns: Latest version

# File lib/ads_common/api_config.rb, line 41
def latest_version
  service_config.keys.select { |service| service.is_a? Integer }.max
end
module_name(version, service) click to toggle source

Returns the full module name for a given service.

Args:

  • version: the API version

  • service: the service name

Returns: The full module name for the given service

# File lib/ads_common/api_config.rb, line 156
def module_name(version, service)
  return [api_name, version.to_s.upcase, service.to_s].join('::')
end
services(version) click to toggle source

Get the list of service names for a given version

Args:

  • version: the API version (as an integer)

Returns: List of names of services available for given version

# File lib/ads_common/api_config.rb, line 82
def services(version)
  service_config[version]
end
subdir(version, service) click to toggle source

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

Args:

  • version: the API version

  • service: the name of the API service

Returns: The subdir infix

# File lib/ads_common/api_config.rb, line 127
def subdir(version, service)
  return nil if subdir_config().nil?
  subdir_config()[[version, service]]
end
version_has_service(version, service) click to toggle source

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/ads_common/api_config.rb, line 60
def version_has_service(version, service)
  return service_config.include?(version) &&
      service_config[version].include?(service)
end
versions() click to toggle source

Get the available API versions.

Returns: List of versions available

# File lib/ads_common/api_config.rb, line 32
def versions
  service_config.keys
end