Module: Oahu::Config

Included in:
Oahu
Defined in:
lib/oahu/config.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

DEFAULT_ADAPTER =

The HTTP connection adapter that will be used to connect if none is set

:net_http
DEFAULT_CONNECTION_OPTIONS =

The Faraday connection options if none is set

{}
DEFAULT_CLIENT_ID =

The client ID if none is set

nil
DEFAULT_CONSUMER_ID =

The consumer ID if none is set

nil
DEFAULT_CONSUMER_SECRET =

The consumer secret if none is set

nil
DEFAULT_ENDPOINT =

The endpoint that will be used to connect if none is set

'https://app.oahu.fr'
DEFAULT_OAUTH_TOKEN =

The oauth token if none is set

nil
DEFAULT_OAUTH_TOKEN_SECRET =

The oauth token secret if none is set

nil
DEFAULT_CACHE_STORE =
nil
DEFAULT_USER_AGENT =

The value sent in the ‘User-Agent’ header if none is set

"Oahu Ruby Gem #{Oahu::VERSION}"
VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring a Oahu::Client

[
  :adapter,
  :connection_options,
  :client_id, 
  :consumer_id,
  :consumer_secret,
  :endpoint,
  :user_agent,
  :cache_store
]

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



54
55
56
# File 'lib/oahu/config.rb', line 54

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:

  • _self (Oahu::Config)

    the object that the method was called on



59
60
61
62
# File 'lib/oahu/config.rb', line 59

def configure
  yield self
  self
end

#optionsObject

Create a hash of options and their values



65
66
67
68
69
# File 'lib/oahu/config.rb', line 65

def options
  options = {}
  VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
  options
end

#resetObject

Reset all configuration options to defaults



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/oahu/config.rb', line 72

def reset
  self.adapter            = DEFAULT_ADAPTER
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
  self.client_id          = DEFAULT_CLIENT_ID
  self.consumer_id        = DEFAULT_CONSUMER_ID
  self.consumer_secret    = DEFAULT_CONSUMER_SECRET
  self.endpoint           = DEFAULT_ENDPOINT
  self.user_agent         = DEFAULT_USER_AGENT
  self.cache_store        = DEFAULT_CACHE_STORE
  self
end