Repository URL to install this package:
|
Version:
0.1.0 ▾
|
module FieldEdgeApi
module Configuration
VALID_OPTIONS_KEYS = [
:partner_key,
:company_key,
:access_token,
:adapter,
:endpoint
].freeze
# By default don't set the email.
DEFAULT_PARTNER_KEY = nil
# By default don't set the password.
DEFAULT_COMPANY_KEY = nil
# By default don't set the access token.
DEFAULT_ACCESS_TOKEN = nil
# Use the default Faraday adapter.
DEFAULT_ADAPTER = Faraday.default_adapter
# By default use the main api URL.
DEFAULT_ENDPOINT = 'api.fieldedge.com'.freeze
attr_accessor *VALID_OPTIONS_KEYS
# Convenience method to allow configuration options to be set in a block
def configure
yield self
end
def options
VALID_OPTIONS_KEYS.inject({}) do |option, key|
option.merge!(key => send(key))
end
end
# When this module is extended, reset all settings.
def self.extended(base)
base.reset
end
# Reset all configuration settings to default values.
def reset
self.partner_key = DEFAULT_PARTNER_KEY
self.company_key = DEFAULT_COMPANY_KEY
self.access_token = DEFAULT_ACCESS_TOKEN
self.endpoint = DEFAULT_ENDPOINT
self.adapter = DEFAULT_ADAPTER
end
end
end