Module: TropoRest::Configuration

Included in:
TropoRest
Defined in:
lib/tropo_rest/configuration.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

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

By default, don’t set a username

nil.freeze
DEFAULT_PASSWORD =

By default, don’t set a password

nil.freeze
DEFAULT_ADAPTER =

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

Faraday.default_adapter.freeze
DEFAULT_ENDPOINT =
Note:

You shouldn’t set this unless you don’t want to use SSL.

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

'https://api.tropo.com/v1/'.freeze
DEFAULT_SESSION_ENDPOINT =
Note:

You shouldn’t set this unless you don’t want to use SSL.

The endpoint that will be used for the creating sessions and sending signals

'https://api.tropo.com/1.0/'.freeze
DEFAULT_USER_AGENT =

The user agent that will be sent to the API endpoint if none is set

"TropoRest Ruby Gem #{TropoRest::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



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

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:



39
40
41
# File 'lib/tropo_rest/configuration.rb', line 39

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



44
45
46
47
48
# File 'lib/tropo_rest/configuration.rb', line 44

def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end

#resetObject

Reset all configuration options to defaults



51
52
53
54
55
56
57
58
59
# File 'lib/tropo_rest/configuration.rb', line 51

def reset
  self.username           = DEFAULT_USERNAME
  self.password           = DEFAULT_PASSWORD
  self.adapter            = DEFAULT_ADAPTER
  self.endpoint           = DEFAULT_ENDPOINT
  self.session_endpoint   = DEFAULT_SESSION_ENDPOINT
  self.user_agent         = DEFAULT_USER_AGENT
  self
end