Module: ESPN::Configuration

Included in:
ESPN
Defined in:
lib/espn/configuration.rb

Overview

Public: All methods useful for configuration. This module should be extended in the ESPN module, so ESPN can be configured.

Examples

module ESPN
  extend Configuration
end

Constant Summary collapse

VALID_OPTIONS_KEYS =

Public: Array of all configuration options for an ESPN::Client.

[:adapter, :api_version, :proxy, :api_key, :timeout,
:open_timeout, :user_agent].freeze
DEFAULT_ADAPTER =

Public: The default adapter used for requests.

Faraday.default_adapter
DEFAULT_API_VERSION =

Public: The default API Version.

1
DEFAULT_USER_AGENT =

Public: The default user agent.

"ESPN Ruby Gem #{ESPN::VERSION}".freeze
DEFAULT_TIMEOUT =

Public: The default timeout for HTTP Requests.

10

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Internal: Hook when this module is extended in another, we call #reset.

Returns nothing.



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

def self.extended(base)
  base.reset
end

Instance Method Details

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

Public: The ability to configure ESPN default options.

Examples

ESPN.configure do |c|
  c.api_key = 'abc123'
end

Yields ESPN::Configuration.

Yields:

  • (_self)

Yield Parameters:



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

def configure
  yield self
end

#optionsObject

Public: Get all valid options with their defaults.

Returns a Hash.



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

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

#resetObject

Public: Reset all valid options to their defaults.

Returns nothing.



66
67
68
69
70
71
72
73
74
# File 'lib/espn/configuration.rb', line 66

def reset
  self.adapter                = DEFAULT_ADAPTER
  self.api_version            = DEFAULT_API_VERSION
  self.user_agent             = DEFAULT_USER_AGENT
  self.timeout                = DEFAULT_TIMEOUT
  self.open_timeout           = DEFAULT_TIMEOUT
  self.api_key                = nil
  self.proxy                  = nil
end