Module: Formi9::Configuration

Included in:
Formi9
Defined in:
lib/formi9/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

[
  :partner_id, 
  :username,
  :password,
  :adapter,
  :connection_options,
  :host,
  :endpoint,
  :format,
  :proxy,
  :user_agent,
  :per_page,
  :timeout,
  :ssl_verify,
  :open_timeout,
  :b2b_encryption_algorithm,
  :b2b_encryption_cipher_mode,
  :b2b_encryption_key,
  :b2b_encryption_iv,
].freeze
DEFAULT_ACCESS_TOKEN =

By default, don’t set an access token

nil
DEFAULT_PER_PAGE =

By default, return 20 resources per page when there is an pagination.

20
DEFAULT_ADAPTER =
Note:

The default faraday adapter is Net::HTTP.

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

Faraday.default_adapter
DEFAULT_CONNECTION_OPTIONS =

By default, don’t set connection options.

{}
DEFAULT_TIMEOUT =

Default timeout time is 20 seconds

20
DEFAULT_OPEN_TIMEOUT =

By default, the open timeout is 20 seconds.

20
DEFAULT_SSL_VERIFY =
false
DEFAULT_ENDPOINT =

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

'https://www.formi9.com/FormI9Api/partner/v2.0/'.freeze
DEFAULT_FORMAT =
Note:

JSON is the only available format at this time

The response format appended to the path and sent in the ‘Accept’ header if none is set

:json
DEFAULT_B2B_ENCRYPTION_ALGORITHM =
OpenSSL::Cipher::AES256
DEFAULT_B2B_ENCRYPTION_CIPHER_MODE =
:CBC
DEFAULT_PROXY =

By default, don’t use a proxy server

nil
DEFAULT_USER_AGENT =

The user agent that will be sent to the API endpoint if none is set

"formi9.com Ruby Gem #{Formi9::VERSION}".freeze
VALID_FORMATS =

An array of valid request/response formats

[:json].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



77
78
79
# File 'lib/formi9/configuration.rb', line 77

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:



82
83
84
# File 'lib/formi9/configuration.rb', line 82

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



87
88
89
90
91
# File 'lib/formi9/configuration.rb', line 87

def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end

#resetObject

Reset all configuration options to defaults



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/formi9/configuration.rb', line 94

def reset
  self.adapter            = DEFAULT_ADAPTER
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
  self.endpoint           = DEFAULT_ENDPOINT
  self.format             = DEFAULT_FORMAT
  self.proxy              = DEFAULT_PROXY
  self.user_agent         = DEFAULT_USER_AGENT
  self.per_page           = DEFAULT_PER_PAGE
  self.timeout            = DEFAULT_TIMEOUT
  self.open_timeout       = DEFAULT_OPEN_TIMEOUT
  self.ssl_verify         = DEFAULT_SSL_VERIFY
  self.b2b_encryption_algorithm   = DEFAULT_B2B_ENCRYPTION_ALGORITHM
  self.b2b_encryption_cipher_mode = DEFAULT_B2B_ENCRYPTION_CIPHER_MODE
end