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 =
'2.0.0'

Instance Method Summary collapse

Instance Method Details

#api_nameObject

Get the API name.

Raises:

  • (NotImplementedError)


87
88
89
# File 'lib/ads_common/api_config.rb', line 87

def api_name
  raise NotImplementedError, 'api_name not overriden.'
end

#api_pathObject

Get the API path.



92
93
94
# File 'lib/ads_common/api_config.rb', line 92

def api_path
  return api_name.to_s.snakecase
end

#default_config_filenameObject

Get the default filename for the config file.

Raises:

  • (NotImplementedError)


97
98
99
# File 'lib/ads_common/api_config.rb', line 97

def default_config_filename
  raise NotImplementedError, 'default_config_filename not overriden.'
end

#default_versionObject

Get the default API version.

Returns: Default version



70
71
72
# File 'lib/ads_common/api_config.rb', line 70

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



141
142
143
144
145
# 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) ⇒ Object

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



110
111
112
113
114
115
116
# 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) ⇒ Object

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


208
209
210
# 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) ⇒ 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


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# 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) ⇒ Object

Does the current config contain the given version?

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



50
51
52
# File 'lib/ads_common/api_config.rb', line 50

def has_version(version)
  return !config(version).nil?
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



169
170
171
# 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_versionObject

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



156
157
158
# 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) ⇒ 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



82
83
84
# File 'lib/ads_common/api_config.rb', line 82

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



127
128
129
130
# 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) ⇒ Object

Does the given version exist and contain the given service?

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



60
61
62
63
# 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

#versionsObject

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