Module: StatRaptor::Config

Included in:
StatRaptor
Defined in:
lib/statraptor/config.rb

Overview

Defines constants and methods related to configuration Inspired by the Twitter gem config: bit.ly/A2RPvv

Constant Summary collapse

DEFAULT_ENDPOINT =

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

"https://statraptor.com"
DEFAULT_USER_AGENT =

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

"StatRaptor Ruby Gem #{StatRaptor::VERSION}"
DEFAULT_TIMEOUT =

The timeout (in milliseconds) that will be used if none is set

5000
DEFAULT_PLATFORM_CREDENTIALS =

The default platform_credentials if none are set

nil
DEFAULT_DISABLE_SSL_PEER_VERIFICATION =

If you’re hitting a non-verifiable SSL server then you’ll have to disable peer verification to make SSL work

false
HTTP_HEADERS =
{
  'Accept' => 'application/json',
  'User-Agent' => "StatRaptor RubyGem #{StatRaptor::VERSION} - http://github.com/chargify/statraptor",
}
VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring a StatRaptor::Client

[
  :endpoint,
  :user_agent,
  :timeout,
  :platform_credentials,
  :disable_ssl_peer_verification
]

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



41
42
43
# File 'lib/statraptor/config.rb', line 41

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:



46
47
48
49
# File 'lib/statraptor/config.rb', line 46

def configure
  yield self
  self
end

#full_uri(path) ⇒ Object



72
73
74
# File 'lib/statraptor/config.rb', line 72

def full_uri(path)
  "#{StatRaptor.endpoint}#{path}"
end

#optionsObject

Create a hash of options and their values



52
53
54
55
56
# File 'lib/statraptor/config.rb', line 52

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

#resetObject

Reset all configuration options to defaults



59
60
61
62
63
64
65
66
# File 'lib/statraptor/config.rb', line 59

def reset
  self.endpoint                      = DEFAULT_ENDPOINT
  self.user_agent                    = DEFAULT_USER_AGENT
  self.timeout                       = DEFAULT_TIMEOUT
  self.platform_credentials          = DEFAULT_PLATFORM_CREDENTIALS
  self.disable_ssl_peer_verification = DEFAULT_DISABLE_SSL_PEER_VERIFICATION
  self
end

#timeout_in_secondsObject



68
69
70
# File 'lib/statraptor/config.rb', line 68

def timeout_in_seconds
  self.timeout / 1000.0
end