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
Get the API name.
# File lib/ads_common/api_config.rb, line 87 def api_name raise NotImplementedError, 'api_name not overriden.' end
Get the API path.
# File lib/ads_common/api_config.rb, line 92 def api_path return api_name.to_s.snakecase end
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
Get the default API version.
Returns: Default version
# File lib/ads_common/api_config.rb, line 70 def default_version nil end
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
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
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
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
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
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
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
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
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
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
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
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