Module: Elmas::Config

Includes:
ThreadsafeAttributes
Included in:
Elmas
Defined in:
lib/elmas/config.rb

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash

%i(
  access_token
  adapter
  client_id
  client_secret
  connection_options
  redirect_uri
  response_format
  user_agent
  endpoint
  division
  base_url
  refresh_token
  logger
).freeze
DEFAULT_ACCESS_TOKEN =

By default, don’t set a user access token

""
DEFAULT_REFRESH_TOKEN =
""
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_CLIENT_ID =

By default, client id should be set in .env

""
DEFAULT_CLIENT_SECRET =

By default, client secret should be set in .env

""
DEFAULT_CONNECTION_OPTIONS =

By default, don’t set any connection options

{}.freeze
DEFAULT_BASE_URL =
"https://start.exactonline.nl"
DEFAULT_ENDPOINT =

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

"api/v1"
DEFAULT_DIVISION =

the division code you want to connect with

""
DEFAULT_FORMAT =

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

:json
DEFAULT_REDIRECT_URI =
"https://www.getpostman.com/oauth2/callback"
DEFAULT_USER_AGENT =

By default, don’t set user agent

nil
VALID_FORMATS =

An array of valid request/response formats

[:json].freeze
DEFAULT_LOGGER =
::Logger.new(STDOUT)

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



72
73
74
# File 'lib/elmas/config.rb', line 72

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:

  • _self (Elmas::Config)

    the object that the method was called on



77
78
79
# File 'lib/elmas/config.rb', line 77

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



82
83
84
85
86
# File 'lib/elmas/config.rb', line 82

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

#resetObject

Reset all configuration options to defaults



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/elmas/config.rb', line 89

def reset
  self.access_token       = DEFAULT_ACCESS_TOKEN
  self.adapter            = DEFAULT_ADAPTER
  self.client_id          = DEFAULT_CLIENT_ID
  self.client_secret      = DEFAULT_CLIENT_SECRET
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
  self.redirect_uri       = DEFAULT_REDIRECT_URI
  self.endpoint           = DEFAULT_ENDPOINT
  self.division           = DEFAULT_DIVISION
  self.base_url           = DEFAULT_BASE_URL
  self.response_format    = DEFAULT_FORMAT
  self.user_agent         = DEFAULT_USER_AGENT
  self.refresh_token      = DEFAULT_REFRESH_TOKEN
  self.logger             = DEFAULT_LOGGER
end