Module: Amara::Configuration

Included in:
Amara
Defined in:
lib/amara/configuration.rb

Constant Summary collapse

VALID_OPTIONS_KEYS =
[
  :api_username,
  :api_key,
  :adapter,
  :endpoint,
  :user_agent,
  :raise_errors
].freeze
DEFAULT_API_USERNAME =

this you need to get from amara - go register!

nil
DEFAULT_API_KEY =
nil
DEFAULT_ADAPTER =

Adapters are whatever Faraday supports - I like excon alot, so I’m defaulting it

:excon
DEFAULT_ENDPOINT =

The api endpoint to get REST

'https://www.amara.org/api2/partners'.freeze
DEFAULT_USER_AGENT =

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

"Amara Ruby Gem #{Amara::VERSION}".freeze
DEFAULT_RAISE_ERRORS =

by default, raise errors instead of returning them

true

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



38
39
40
# File 'lib/amara/configuration.rb', line 38

def self.extended(base)
  base.reset!
end

.keysObject



43
44
45
# File 'lib/amara/configuration.rb', line 43

def keys
  VALID_OPTIONS_KEYS
end

Instance Method Details

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

Convenience method to allow for global setting of configuration options

Yields:

  • (_self)

Yield Parameters:



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

def configure
  yield self
end

#optionsObject



48
49
50
51
52
# File 'lib/amara/configuration.rb', line 48

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

#reset!Object

Reset configuration options to their defaults



55
56
57
58
59
60
61
62
63
# File 'lib/amara/configuration.rb', line 55

def reset!
  self.api_username = DEFAULT_API_USERNAME
  self.api_key      = DEFAULT_API_KEY
  self.adapter      = DEFAULT_ADAPTER
  self.endpoint     = DEFAULT_ENDPOINT
  self.user_agent   = DEFAULT_USER_AGENT
  self.raise_errors = DEFAULT_RAISE_ERRORS
  self
end