Module: SFPark::Configuration

Included in:
SFPark
Defined in:
lib/sfpark/configuration.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring a SfPark::API

[
:adapter,
:endpoint,
:proxy,
:response,
:user_agent,
:faraday_options].freeze
DEFAULT_ADAPTER =

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

:net_http
DEFAULT_ENDPOINT =

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

'http://api.sfpark.org/sfpark/rest'.freeze
DEFAULT_RESPONSE =
Note:

JSON is preferred over XML because it is more concise and faster to parse.

The response format appended to the path and sent in the 'Accept' header if none is set

:json
DEFAULT_PROXY =

By default, don't use a proxy server

nil
DEFAULT_USER_AGENT =

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

"SFPark Ruby Gem #{SFPark::VERSION}".freeze
DEFAULT_FARADAY_OPTIONS =
{}.freeze

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



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

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:



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

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



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

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

#resetObject

Reset all configuration options to defaults



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

def reset
  self.adapter                = DEFAULT_ADAPTER
  self.endpoint               = DEFAULT_ENDPOINT
  self.proxy                  = DEFAULT_PROXY
  self.user_agent             = DEFAULT_USER_AGENT
  self.response               = DEFAULT_RESPONSE
  self.faraday_options        = DEFAULT_FARADAY_OPTIONS
  self
end