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, :api_key, :proxy, :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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#adapterObject

Public: Gets/Sets the Symbol adapter.



21
22
23
# File 'lib/espn/configuration.rb', line 21

def adapter
  @adapter
end

#api_keyObject

Public: Gets/Sets the String api key.



27
28
29
# File 'lib/espn/configuration.rb', line 27

def api_key
  @api_key
end

#api_versionObject

Public: Gets/Sets the Fixnum api version.



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

def api_version
  @api_version
end

#open_timeoutObject

Public: Gets/Sets the Fixnum open timeout.



30
31
32
# File 'lib/espn/configuration.rb', line 30

def open_timeout
  @open_timeout
end

#proxyObject

Public: Gets/Sets the String proxy.



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

def proxy
  @proxy
end

#timeoutObject

Public: Gets/Sets the Fixnum timeout.



36
37
38
# File 'lib/espn/configuration.rb', line 36

def timeout
  @timeout
end

#user_agentObject

Public: Gets/Sets the String user agent.



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

def user_agent
  @user_agent
end

Class Method Details

.extended(base) ⇒ Object

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

Returns nothing.



56
57
58
# File 'lib/espn/configuration.rb', line 56

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:



69
70
71
# File 'lib/espn/configuration.rb', line 69

def configure
  yield self
end

#optionsObject

Public: Get all valid options with their defaults.

Returns a Hash.



76
77
78
# File 'lib/espn/configuration.rb', line 76

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.



83
84
85
86
87
88
89
90
91
# File 'lib/espn/configuration.rb', line 83

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