Class: Elements::ElementsConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/elements/elements_configuration.rb

Overview

Configurations:

api_base: The base URL of the Elements API, see elements-pay.readme.io/reference/set-up-elements.

api_key: The client token required to execute requests, see elements-pay.readme.io/reference/fetch-client-token.

max_network_retries, min_network_retry_delay, max_network_retry_delay: The client has the ability to perform automatic retries with exponential backoff, you may configure how the client retries with these variables, setting max_network_retries to 0 disable retries.

ssl_ca_file: The location of a file containing a bundle of CA certificates, the library included one under lib/elements/certs and will use that as default.

ssl_verify_certs: You may disable SSL verification by setting this to false.

logger: When set, the library will log execution information to the prompt location. You may change the verbosity by supplying a log_level config.

Constant Summary collapse

SANDBOX_URL =
'https://api.elements-sandbox.io'
PRODUCTION_URL =
'https://api.elements.io'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeElementsConfiguration

Returns a new instance of ElementsConfiguration.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/elements/elements_configuration.rb', line 30

def initialize
  @api_base = PRODUCTION_URL
  # disable log by default
  @logger = Logger.new('/dev/null')
  @log_level = Logger::DEBUG
  @max_network_retries = 0
  @min_network_retry_delay = 0.5
  @max_network_retry_delay = 2.0
  @ssl_verify_certs = true
  @ssl_ca_file = File.expand_path('certs/cacert.pem', __dir__)
end

Instance Attribute Details

#api_baseObject

Returns the value of attribute api_base.



23
24
25
# File 'lib/elements/elements_configuration.rb', line 23

def api_base
  @api_base
end

#api_keyObject

Returns the value of attribute api_key.



23
24
25
# File 'lib/elements/elements_configuration.rb', line 23

def api_key
  @api_key
end

#log_levelObject

Returns the value of attribute log_level.



25
26
27
# File 'lib/elements/elements_configuration.rb', line 25

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



23
24
25
# File 'lib/elements/elements_configuration.rb', line 23

def logger
  @logger
end

#max_network_retriesObject

Returns the value of attribute max_network_retries.



23
24
25
# File 'lib/elements/elements_configuration.rb', line 23

def max_network_retries
  @max_network_retries
end

#max_network_retry_delayObject

Returns the value of attribute max_network_retry_delay.



23
24
25
# File 'lib/elements/elements_configuration.rb', line 23

def max_network_retry_delay
  @max_network_retry_delay
end

#min_network_retry_delayObject

Returns the value of attribute min_network_retry_delay.



23
24
25
# File 'lib/elements/elements_configuration.rb', line 23

def min_network_retry_delay
  @min_network_retry_delay
end

#ssl_ca_fileObject

Returns the value of attribute ssl_ca_file.



23
24
25
# File 'lib/elements/elements_configuration.rb', line 23

def ssl_ca_file
  @ssl_ca_file
end

#ssl_verify_certsObject

Returns the value of attribute ssl_verify_certs.



23
24
25
# File 'lib/elements/elements_configuration.rb', line 23

def ssl_verify_certs
  @ssl_verify_certs
end

Instance Method Details

#reverse_duplicate_merge(hash) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/elements/elements_configuration.rb', line 62

def reverse_duplicate_merge(hash)
  dup.tap do |instance|
    hash.each do |option, value|
      instance.public_send("#{option}=", value)
    end
  end
end