Module: PostcodeAnywhere::Configuration

Included in:
PostcodeAnywhere
Defined in:
lib/postcode_anywhere/configuration.rb

Constant Summary collapse

VALID_CONNECTION_KEYS =
[
  :endpoint,
  :api_key,
  :method,
  :user_agent
].freeze
VALID_OPTIONS_KEYS =
[:format].freeze
VALID_CONFIG_KEYS =
VALID_CONNECTION_KEYS +
VALID_OPTIONS_KEYS
DEFAULT_METHOD =
:post
DEFAULT_USER_AGENT =
"Postcode Anywhere Ruby Gem/#{PostcodeAnywhere::VERSION}"
DEFAULT_API_KEY =
''
DEFAULT_FORMAT =
:json
DEFAULT_ENDPOINT =
'http://services.postcodeanywhere.co.uk/'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



28
29
30
# File 'lib/postcode_anywhere/configuration.rb', line 28

def self.extended(base)
  base.reset
end

Instance Method Details

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

Yields:

  • (_self)

Yield Parameters:



40
41
42
# File 'lib/postcode_anywhere/configuration.rb', line 40

def configure
  yield self
end

#optionsObject

Return the configuration values set in this module



45
46
47
# File 'lib/postcode_anywhere/configuration.rb', line 45

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

#resetObject



32
33
34
35
36
37
38
# File 'lib/postcode_anywhere/configuration.rb', line 32

def reset
  self.api_key          = DEFAULT_API_KEY
  self.endpoint         = DEFAULT_ENDPOINT
  self.format           = DEFAULT_FORMAT
  self.method           = DEFAULT_METHOD
  self.user_agent       = DEFAULT_USER_AGENT
end