Module: AdsCommon::ApiConfig
- Defined in:
- lib/ads_common/api_config.rb,
lib/ads_common/version.rb
Overview
Contains helper methods for loading and managing the available services. This module is meant to be imported into API-specific modules.
Constant Summary collapse
- CLIENT_LIB_VERSION =
'0.9.9'
Instance Method Summary collapse
-
#api_name ⇒ Object
Get the API name.
-
#api_path ⇒ Object
Get the API path.
-
#auth_server(environment) ⇒ Object
Get the authentication server details for an environment.
-
#default_config_filename ⇒ Object
Get the default filename for the config file.
-
#default_environment ⇒ Object
Get the default environment.
-
#default_version ⇒ Object
Get the default API version.
-
#do_require(version, service) ⇒ Object
Perform the loading of the necessary source files for a version.
-
#endpoint(environment, version, service) ⇒ Object
Get the endpoint for a service on a given environment and API version.
-
#environment_has_version(environment, version) ⇒ Object
Does the given environment exist and contain the given version?.
-
#get_wsdl_base(environment, version) ⇒ Object
Returns WSDL base url defined in Service configuration.
-
#get_wsdls(version) ⇒ Object
Generates an array of WSDL URLs based on defined Services and version supplied.
-
#interface_name(version, service) ⇒ Object
Returns the full interface class name for a given service.
-
#latest_version ⇒ Object
Get the latest API version.
-
#module_name(version, service) ⇒ Object
Returns the full module name for a given service.
-
#services(version) ⇒ Object
Get the list of service names for a given version.
-
#subdir(version, service) ⇒ Object
Get the subdirectory for a service, for a given API version.
-
#version_has_service(version, service) ⇒ Object
Does the given version exist and contain the given service?.
-
#versions ⇒ Object
Get the available API versions.
Instance Method Details
#api_name ⇒ Object
Get the API name.
91 92 93 |
# File 'lib/ads_common/api_config.rb', line 91 def api_name raise NotImplementedError, 'api_name not overriden.' end |
#api_path ⇒ Object
Get the API path.
96 97 98 |
# File 'lib/ads_common/api_config.rb', line 96 def api_path return api_name.to_s.snakecase end |
#auth_server(environment) ⇒ Object
Get the authentication server details for an environment. Allows to override the auth URL via environmental variable.
Args:
-
environment: the service environment to be used
Returns: The full URL for the auth server
157 158 159 |
# File 'lib/ads_common/api_config.rb', line 157 def auth_server(environment) return ENV['ADSAPI_AUTH_URL'] || auth_server_config[environment] end |
#default_config_filename ⇒ Object
Get the default filename for the config file.
110 111 112 |
# File 'lib/ads_common/api_config.rb', line 110 def default_config_filename raise NotImplementedError, 'default_config_filename not overriden.' end |
#default_environment ⇒ Object
Get the default environment.
Returns: Default environment
105 106 107 |
# File 'lib/ads_common/api_config.rb', line 105 def default_environment raise NotImplementedError, 'default_environment not overriden.' end |
#default_version ⇒ Object
Get the default API version.
Returns: Default version
74 75 76 |
# File 'lib/ads_common/api_config.rb', line 74 def default_version nil end |
#do_require(version, service) ⇒ Object
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
170 171 172 173 174 |
# File 'lib/ads_common/api_config.rb', line 170 def do_require(version, service) filename = [api_path, version.to_s, service.to_s.snakecase].join('/') require filename return filename end |
#endpoint(environment, version, service) ⇒ Object
Get the endpoint for a service on a given environment and API version.
Args:
-
environment: the service environment to be used
-
version: the API version
-
service: the name of the API service
Returns: The endpoint URL
124 125 126 127 128 129 130 131 |
# File 'lib/ads_common/api_config.rb', line 124 def endpoint(environment, version, service) base = get_wsdl_base(environment, version) # TODO(dklimkin): Unflatten subdir constants. Cross-API refactor 0.9.0. 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 |
#environment_has_version(environment, version) ⇒ Object
Does the given environment exist and contain the given version?
Returns: Boolean indicating whether the given environment exists and contains the given version
54 55 56 |
# File 'lib/ads_common/api_config.rb', line 54 def environment_has_version(environment, version) return !environment_config(environment, version).nil? end |
#get_wsdl_base(environment, version) ⇒ Object
Returns WSDL base url defined in Service configuration. Allows to override the base URL via environmental variable.
Args:
- environment: environment to use like :SANDBOX or :PRODUCTION
- version: the API version
Returns:
String containing base URL
237 238 239 240 |
# File 'lib/ads_common/api_config.rb', line 237 def get_wsdl_base(environment, version) return ENV['ADSAPI_BASE_URL'] || environment_config(environment, version) end |
#get_wsdls(version) ⇒ Object
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
212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/ads_common/api_config.rb', line 212 def get_wsdls(version) res = {} wsdl_base = get_wsdl_base(default_environment(), version) 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 + '?wsdl' res[service.to_s] = path end return res end |
#interface_name(version, service) ⇒ Object
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
198 199 200 |
# File 'lib/ads_common/api_config.rb', line 198 def interface_name(version, service) return [module_name(version, service), service.to_s].join('::') end |
#latest_version ⇒ Object
Get the latest API version.
Returns: Latest version
44 45 46 |
# File 'lib/ads_common/api_config.rb', line 44 def latest_version service_config.keys.select { |service| service.is_a? Integer }.max end |
#module_name(version, service) ⇒ Object
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
185 186 187 |
# File 'lib/ads_common/api_config.rb', line 185 def module_name(version, service) return [api_name, version.to_s.upcase, service.to_s].join('::') end |
#services(version) ⇒ Object
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
86 87 88 |
# File 'lib/ads_common/api_config.rb', line 86 def services(version) service_config[version] end |
#subdir(version, service) ⇒ Object
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
142 143 144 145 146 |
# File 'lib/ads_common/api_config.rb', line 142 def subdir(version, service) return nil if subdir_config().nil? # TODO(dklimkin): Unflatten subdir constants. Cross-API refactor 0.9.0. subdir_config()[[version, service]] end |
#version_has_service(version, service) ⇒ Object
Does the given version exist and contain the given service?
Returns: Boolean indicating whether the given version exists and contains the given service
64 65 66 67 |
# File 'lib/ads_common/api_config.rb', line 64 def version_has_service(version, service) return service_config.include?(version) && service_config[version].include?(service) end |
#versions ⇒ Object
Get the available API versions.
Returns: List of versions available
35 36 37 |
# File 'lib/ads_common/api_config.rb', line 35 def versions service_config.keys end |