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.11.3'
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.
88 89 90 |
# File 'lib/ads_common/api_config.rb', line 88 def api_name raise NotImplementedError, 'api_name not overriden.' end |
#api_path ⇒ Object
Get the API path.
93 94 95 |
# File 'lib/ads_common/api_config.rb', line 93 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
154 155 156 |
# File 'lib/ads_common/api_config.rb', line 154 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.
107 108 109 |
# File 'lib/ads_common/api_config.rb', line 107 def default_config_filename raise NotImplementedError, 'default_config_filename not overriden.' end |
#default_environment ⇒ Object
Get the default environment.
Returns: Default environment
102 103 104 |
# File 'lib/ads_common/api_config.rb', line 102 def default_environment raise NotImplementedError, 'default_environment not overriden.' end |
#default_version ⇒ Object
Get the default API version.
Returns: Default version
71 72 73 |
# File 'lib/ads_common/api_config.rb', line 71 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
167 168 169 170 171 |
# File 'lib/ads_common/api_config.rb', line 167 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
121 122 123 124 125 126 127 128 |
# File 'lib/ads_common/api_config.rb', line 121 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
51 52 53 |
# File 'lib/ads_common/api_config.rb', line 51 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
235 236 237 238 |
# File 'lib/ads_common/api_config.rb', line 235 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
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/ads_common/api_config.rb', line 209 def get_wsdls(version) res = {} wsdl_base = get_wsdl_base(default_environment(), 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 |
#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
195 196 197 |
# File 'lib/ads_common/api_config.rb', line 195 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
41 42 43 |
# 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) ⇒ 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
182 183 184 |
# File 'lib/ads_common/api_config.rb', line 182 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
83 84 85 |
# File 'lib/ads_common/api_config.rb', line 83 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
139 140 141 142 143 |
# File 'lib/ads_common/api_config.rb', line 139 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
61 62 63 64 |
# File 'lib/ads_common/api_config.rb', line 61 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
32 33 34 |
# File 'lib/ads_common/api_config.rb', line 32 def versions service_config.keys end |