Module: Fcoin::Configuration

Included in:
Fcoin
Defined in:
lib/fcoin/configuration.rb

Constant Summary collapse

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_ENDPOINT =
Note:

There is no reason to use any other endpoint at this time

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

'https://api.fcoin.com/v2/'
DEFAULT_WSS_ENDPOINT =
'wss://api.fcoin.com/v2/ws'
DEFAULT_USER_AGENT =

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

"Fcoin Ruby Gem #{Fcoin::VERSION}".freeze
DEFAULT_PROXY =
nil
DEFAULT_CA_PATH =
%x[ openssl version -a | grep OPENSSLDIR | awk '{print $2}'|sed -e 's/\"//g' ].chomp
DEFAULT_CA_FILE =
"#{DEFAULT_CA_PATH}/ca-certificates.crt"
DEFAULT_MIDDLEWARES =
[]
DEFAULT_API_KEY =
'Fcoin API Public Key'
DEFAULT_SECRET_KEY =
'Fcoin API Secret Key'
DEFAULT_SKIP_VALIDATION =
true
DEFAULT_VALIDATION_SETTING_PATH =
File.expand_path('../config/custom_settings.yml',__FILE__)
DEFAULT_FORMAT_TYPE =

support ruby Hash or JSON. default is ruby Hash

:hash
VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring a Fcoin::API

[
  :adapter,
  :endpoint,
  :wss_endpoint,
  :user_agent,
  :api_key,
  :secret_key,
  :proxy,
  :ca_path,
  :ca_file,
  :middlewares,
  :skip_validation,
  :validation_setting_path,
  :format_type
].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 and load validation setting path



52
53
54
55
# File 'lib/fcoin/configuration.rb', line 52

def self.extended(base)
  base.set_default
  base.load_validation_setting
end

Instance Method Details

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

Convenience method to allow configuration options to be set in block

Yields:

  • (_self)

Yield Parameters:



58
59
60
61
# File 'lib/fcoin/configuration.rb', line 58

def configure
  yield self
  load_validation_setting
end

#load_validation_settingObject

Load a configuration file to use in the gem that config



71
72
73
74
75
76
# File 'lib/fcoin/configuration.rb', line 71

def load_validation_setting
  Config.load_and_set_settings([
    File.expand_path('../config/settings.yml', __FILE__),
    validation_setting_path
  ])
end

#optionsObject

Create a hash of options and their values



64
65
66
67
68
# File 'lib/fcoin/configuration.rb', line 64

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

#set_defaultObject

Set all configuration options to defaults



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fcoin/configuration.rb', line 79

def set_default
  self.adapter                 = DEFAULT_ADAPTER
  self.endpoint                = DEFAULT_ENDPOINT
  self.wss_endpoint            = DEFAULT_WSS_ENDPOINT
  self.user_agent              = DEFAULT_USER_AGENT
  self.api_key                 = DEFAULT_API_KEY
  self.secret_key              = DEFAULT_SECRET_KEY
  self.proxy                   = DEFAULT_PROXY
  self.ca_path                 = DEFAULT_CA_PATH
  self.ca_file                 = DEFAULT_CA_FILE
  self.middlewares             = DEFAULT_MIDDLEWARES
  self.skip_validation         = DEFAULT_SKIP_VALIDATION
  self.validation_setting_path = DEFAULT_VALIDATION_SETTING_PATH
  self.format_type             = DEFAULT_FORMAT_TYPE
end