Module: TAM::Configuration

Included in:
TAM
Defined in:
lib/tam/configuration.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring a API

[
:consumer_key,
:consumer_secret,
:consumer_handler,
:site,
:request_token_path,
:access_token_path,
:authorize_path,
:oauth_scheme,
:oauth_http_method,
:callback_path].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

When this module is extended, set all configuration options to their default values



38
39
40
# File 'lib/tam/configuration.rb', line 38

def self.extended(base)
  base.reset
end

Instance Method Details

#configure(config) {|_self| ... } ⇒ Object

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:



43
44
45
# File 'lib/tam/configuration.rb', line 43

def configure
  yield self
end

#consumer_handlerObject



33
34
35
# File 'lib/tam/configuration.rb', line 33

def consumer_handler
  @consumer_handler
end

#consumer_handler=(consumer_handler) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tam/configuration.rb', line 20

def consumer_handler=(consumer_handler)
  if consumer_handler.class == String
    begin
      @consumer_handler = Object.const_get(consumer_handler).new
    rescue NameError => error
      LOGGER.error 'Application has provided an invalid telco asset marketplace consumer_handler: ' + TAM.consumer_handler
      raise InvalidConsumerHandler.new 'Application has provided an invalid telco asset marketplace consumer_handler: ' + TAM.consumer_handler
    end
  else
    @consumer_handler = consumer_handler
  end
end

#optionsObject

Create a hash of options and their values



63
64
65
# File 'lib/tam/configuration.rb', line 63

def options
  Hash[VALID_OPTIONS_KEYS.map {|key| [key, send(key)] }]
end

#resetObject

Reset all configuration options to defaults



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/tam/configuration.rb', line 68

def reset
  self.consumer_key       = nil
  self.consumer_secret    = nil
  self.consumer_handler   = nil
  self.site               = 'https://telcoassetmarketplace.com'
  self.request_token_path = '/api/1/oauth/request_token'
  self.access_token_path  = '/api/1/oauth/access_token'
  self.authorize_path     = '/web/authorize'
  self.oauth_scheme       = :query_string
  self.oauth_http_method  = :get
  self.callback_path      = 'tamapi'
  self
end