Module: BullionVault::Configuration

Included in:
BullionVault
Defined in:
lib/bullion_vault/configuration.rb

Constant Summary collapse

VALID_OPTIONS_KEYS =
[
  :adapter,
  :user_login,
  :user_password,
  :endpoint,
  :format,
  :proxy,
  :cookie,
  :user_agent
].freeze
VALID_FORMATS =
[:xml].freeze
DEFAULT_ADAPTER =

The default faraday adapter is Net::HTTP.

Faraday.default_adapter
DEFAULT_USER_LOGIN =
nil
DEFAULT_USER_PASSWORD =
nil
DEFAULT_ENDPOINT =
'https://live.bullionvault.com/'.freeze
DEFAULT_FORMAT =
'xml'.freeze
DEFAULT_PROXY =
nil
nil
DEFAULT_USER_AGENT =
"BullionVault Ruby Gem #{BullionVault::VERSION}".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



33
34
35
# File 'lib/bullion_vault/configuration.rb', line 33

def self.extended(base)
  base.reset
end

Instance Method Details

#authenticateObject



61
62
63
64
# File 'lib/bullion_vault/configuration.rb', line 61

def authenticate
  client = Client.new
  client.authenticate ? (BullionVault.cookie = client.cookie and true) : false
end

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

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:



38
39
40
41
# File 'lib/bullion_vault/configuration.rb', line 38

def configure
  yield self
  self
end

#optionsObject

Create a hash of options and their values



44
45
46
# File 'lib/bullion_vault/configuration.rb', line 44

def options
  Hash[VALID_OPTIONS_KEYS.map {|key| [key, public_send(key)] }]
end

#resetObject

Reset all configuration options to defaults



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bullion_vault/configuration.rb', line 49

def reset
  self.adapter            = DEFAULT_ADAPTER
  self.         = DEFAULT_USER_LOGIN
  self.user_password      = DEFAULT_USER_PASSWORD
  self.endpoint           = DEFAULT_ENDPOINT
  self.format             = DEFAULT_FORMAT
  self.proxy              = DEFAULT_PROXY
  self.cookie             = DEFAULT_COOKIE
  self.user_agent         = DEFAULT_USER_AGENT
  self
end