Module: GamesRadarApi::Configuration

Included in:
GamesRadarApi
Defined in:
lib/games_radar_api/configuration.rb

Constant Summary collapse

VALID_CONNECTION_KEYS =
[:adapter,:endpoint,:user_agent,:method,:proxy].freeze
VALID_OPTIONS_KEYS =
[:api_key,:format].freeze
VALID_CONFIG_KEYS =
VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
DEFAULT_ADAPTER =
Faraday.default_adapter.freeze
DEFAULT_ENDPOINT =
'http://api.gamesradar.com'.freeze
DEFAULT_METHOD =
'get'.freeze
DEFAULT_USER_AGENT =
"Games Radar API Gem #{GamesRadarApi::VERSION}".freeze
DEFAULT_API_KEY =
nil
DEFAULT_FORMAT =
:xml
DEFAULT_PROXY =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Make sure we have the default values set when we get ‘extended’



24
25
26
# File 'lib/games_radar_api/configuration.rb', line 24

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:



29
30
31
# File 'lib/games_radar_api/configuration.rb', line 29

def configure
  yield self
end

#optionsObject

Create a has of options and their values



34
35
36
# File 'lib/games_radar_api/configuration.rb', line 34

def options
  Hash[* VALID_CONFIG_KEYS.map { |key| [key,send(key)] }.flatten ]
end

#resetObject

Reset all configuration options to defaults



39
40
41
42
43
44
45
46
47
48
# File 'lib/games_radar_api/configuration.rb', line 39

def reset
  self.adapter    = DEFAULT_ADAPTER
  self.endpoint   = DEFAULT_ENDPOINT
  self.method     = DEFAULT_METHOD
  self.user_agent = DEFAULT_USER_AGENT

  self.api_key    = DEFAULT_API_KEY
  self.format     = DEFAULT_FORMAT
  self.proxy      = DEFAULT_PROXY
end