Class: Zenbox::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/zenbox/configuration.rb

Overview

Used to set up and modify settings for the notifier.

Constant Summary collapse

OPTIONS =
[:api_key, :host, :http_open_timeout, :http_read_timeout,
:port, :proxy_host, :proxy_pass, :proxy_port, :proxy_user, :secure,
:use_system_ssl_cert_chain].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



50
51
52
53
54
55
56
# File 'lib/zenbox/configuration.rb', line 50

def initialize
  @secure                   = false
  @use_system_ssl_cert_chain= false
  @host                     = 'zenbox.me'
  @http_open_timeout        = 2
  @http_read_timeout        = 5
end

Instance Attribute Details

#api_keyObject

The API key for your Zenbox account.



11
12
13
# File 'lib/zenbox/configuration.rb', line 11

def api_key
  @api_key
end

#hostObject

The host to connect to (defaults to zenbox.me).



14
15
16
# File 'lib/zenbox/configuration.rb', line 14

def host
  @host
end

#http_open_timeoutObject

The HTTP open timeout in seconds (defaults to 2).



27
28
29
# File 'lib/zenbox/configuration.rb', line 27

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutObject

The HTTP read timeout in seconds (defaults to 5).



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

def http_read_timeout
  @http_read_timeout
end

#loggerObject

The logger used by Zenbox



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

def logger
  @logger
end

#portObject

The port on which your Zenbox server runs (defaults to 443 for secure connections, 80 for insecure connections).



18
19
20
# File 'lib/zenbox/configuration.rb', line 18

def port
  @port
end

#proxy_hostObject

The hostname of your proxy server (if using a proxy)



33
34
35
# File 'lib/zenbox/configuration.rb', line 33

def proxy_host
  @proxy_host
end

#proxy_passObject

The password to use when logging into your proxy server (if using a proxy)



42
43
44
# File 'lib/zenbox/configuration.rb', line 42

def proxy_pass
  @proxy_pass
end

#proxy_portObject

The port of your proxy server (if using a proxy)



36
37
38
# File 'lib/zenbox/configuration.rb', line 36

def proxy_port
  @proxy_port
end

#proxy_userObject

The username to use when logging into your proxy server (if using a proxy)



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

def proxy_user
  @proxy_user
end

#secureObject Also known as: secure?

true for https connections, false for http connections.



21
22
23
# File 'lib/zenbox/configuration.rb', line 21

def secure
  @secure
end

#use_system_ssl_cert_chainObject Also known as: use_system_ssl_cert_chain?

true to use whatever CAs OpenSSL has installed on your system. false to use the ca-bundle.crt file included in Zenbox itself (recommended and default)



24
25
26
# File 'lib/zenbox/configuration.rb', line 24

def use_system_ssl_cert_chain
  @use_system_ssl_cert_chain
end

Instance Method Details

#[](option) ⇒ Object

Allows config options to be read like a hash

Parameters:

  • option (Symbol)

    Key for a given attribute



62
63
64
# File 'lib/zenbox/configuration.rb', line 62

def [](option)
  send(option)
end

#ca_bundle_pathObject



92
93
94
95
96
97
98
# File 'lib/zenbox/configuration.rb', line 92

def ca_bundle_path
  if use_system_ssl_cert_chain? && File.exist?(OpenSSL::X509::DEFAULT_CERT_FILE)
    OpenSSL::X509::DEFAULT_CERT_FILE
  else
    local_cert_path # ca-bundle.crt built from source, see resources/README.md
  end
end

#local_cert_pathObject



100
101
102
# File 'lib/zenbox/configuration.rb', line 100

def local_cert_path
  File.expand_path(File.join("..", "..", "..", "resources", "ca-bundle.crt"), __FILE__)
end

#merge(hash) ⇒ Object

Returns a hash of all configurable options merged with hash

Parameters:

  • hash (Hash)

    A set of configuration options that will take precedence over the defaults



76
77
78
# File 'lib/zenbox/configuration.rb', line 76

def merge(hash)
  to_hash.merge(hash)
end

#protocolObject



84
85
86
87
88
89
90
# File 'lib/zenbox/configuration.rb', line 84

def protocol
  if secure?
    'https'
  else
    'http'
  end
end

#to_hashObject

Returns a hash of all configurable options



67
68
69
70
71
# File 'lib/zenbox/configuration.rb', line 67

def to_hash
  OPTIONS.inject({}) do |hash, option|
    hash.merge(option.to_sym => send(option))
  end
end