Module: Besepa::Utils::ApiConfig

Included in:
Besepa
Defined in:
lib/besepa/utils/config.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

DEFAULT_API_KEY =

The consumer key if none is set

nil
DEFAULT_ENDPOINT =

The endpoint that will be used to connect if none is set

'https://sandbox.besepa.com'
VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring api objects

[
  :api_key,
  :endpoint,
  :ssl
]

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



24
25
26
# File 'lib/besepa/utils/config.rb', line 24

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

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

Yields:

  • (_self)

Yield Parameters:



29
30
31
32
# File 'lib/besepa/utils/config.rb', line 29

def configure
  yield self
  self
end

#optionsObject

Create a hash of options and their values



35
36
37
38
39
# File 'lib/besepa/utils/config.rb', line 35

def options
  options = {}
  VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
  options
end

#resetObject

Reset all configuration options to defaults



42
43
44
45
46
# File 'lib/besepa/utils/config.rb', line 42

def reset
  self.api_key            = DEFAULT_API_KEY
  self.endpoint           = DEFAULT_ENDPOINT
  self
end