Module: Surveygizmo::Configuration

Included in:
Surveygizmo
Defined in:
lib/surveygizmo/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 API

[
:username,
:password,
:endpoint,
:user_agent].freeze
DEFAULT_USERNAME =

There is no default

nil
DEFAULT_PASSWORD =

There is no default

nil
DEFAULT_ENDPOINT =

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

'https://restapi.surveygizmo.com/v1/'.freeze
DEFAULT_USER_AGENT =

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

"Surveygizmo Ruby Gem #{Surveygizmo::VERSION}".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



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

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:



35
36
37
# File 'lib/surveygizmo/configuration.rb', line 35

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



40
41
42
43
44
# File 'lib/surveygizmo/configuration.rb', line 40

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

#resetObject

Reset all configuration options to defaults



47
48
49
50
51
52
53
# File 'lib/surveygizmo/configuration.rb', line 47

def reset
  self.endpoint           = DEFAULT_ENDPOINT
  self.username           = DEFAULT_USERNAME
  self.password           = DEFAULT_PASSWORD
  self.user_agent         = DEFAULT_USER_AGENT
  self
end