Module: ArmoryApi::Configuration

Included in:
ArmoryApi
Defined in:
lib/armory_api/configuration.rb

Constant Summary collapse

VALID_OPTIONS_KEYS =
[
  :region,
  :locale,
  :realm,
  :endpoint,
  :user_agent,
  :connection_options,
  :middleware
].freeze
DEFAULT_REGION =
'us'
DEFAULT_LOCALE =
'en_US'
DEFAULT_ENDPOINT =
"http://#{DEFAULT_REGION}.battle.net"
DEFAULT_USER_AGENT =
"ArmoryApi Ruby Gem #{ArmoryApi::VERSION}".freeze
DEFAULT_CONNECTION_OPTIONS =
{
  headers: {
    accept: 'application/json',
    user_agent: DEFAULT_USER_AGENT
  },
  raw: true
}
DEFAULT_MIDDLEWARE =
Faraday::Builder.new do |builder|
  builder.request :json

  builder.use Faraday::Response::RaiseArmoryApiError
  builder.use FaradayMiddleware::Mashify
  builder.use FaradayMiddleware::ParseJson

  builder.adapter Faraday.default_adapter
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



41
42
43
# File 'lib/armory_api/configuration.rb', line 41

def self.extended(base)
  base.reset
end

Instance Method Details

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

Yields:

  • (_self)

Yield Parameters:



45
46
47
# File 'lib/armory_api/configuration.rb', line 45

def configure
  yield self
end

#optionsObject



49
50
51
# File 'lib/armory_api/configuration.rb', line 49

def options
  VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
end

#resetObject



53
54
55
56
57
58
59
60
61
# File 'lib/armory_api/configuration.rb', line 53

def reset
  self.region     = DEFAULT_REGION
  self.locale     = DEFAULT_LOCALE
  self.realm      = nil
  self.endpoint   = DEFAULT_ENDPOINT
  self.user_agent = DEFAULT_USER_AGENT
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
  self.middleware = DEFAULT_MIDDLEWARE
end