Class: Zenbox::Configuration
- Inherits:
-
Object
- Object
- Zenbox::Configuration
- 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
-
#api_key ⇒ Object
The API key for your Zenbox account.
-
#host ⇒ Object
The host to connect to (defaults to zenboxapp.com).
-
#http_open_timeout ⇒ Object
The HTTP open timeout in seconds (defaults to 2).
-
#http_read_timeout ⇒ Object
The HTTP read timeout in seconds (defaults to 5).
-
#logger ⇒ Object
The logger used by Zenbox.
-
#port ⇒ Object
The port on which your Zenbox server runs (defaults to 443 for secure connections, 80 for insecure connections).
-
#proxy_host ⇒ Object
The hostname of your proxy server (if using a proxy).
-
#proxy_pass ⇒ Object
The password to use when logging into your proxy server (if using a proxy).
-
#proxy_port ⇒ Object
The port of your proxy server (if using a proxy).
-
#proxy_user ⇒ Object
The username to use when logging into your proxy server (if using a proxy).
-
#secure ⇒ Object
(also: #secure?)
true
for https connections,false
for http connections. -
#use_system_ssl_cert_chain ⇒ Object
(also: #use_system_ssl_cert_chain?)
true
to use whatever CAs OpenSSL has installed on your system.
Instance Method Summary collapse
-
#[](option) ⇒ Object
Allows config options to be read like a hash.
- #ca_bundle_path ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #local_cert_path ⇒ Object
-
#merge(hash) ⇒ Object
Returns a hash of all configurable options merged with
hash
. - #protocol ⇒ Object
-
#to_hash ⇒ Object
Returns a hash of all configurable options.
Constructor Details
#initialize ⇒ Configuration
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 = 'zenboxapp.com' @http_open_timeout = 2 @http_read_timeout = 5 end |
Instance Attribute Details
#api_key ⇒ Object
The API key for your Zenbox account.
11 12 13 |
# File 'lib/zenbox/configuration.rb', line 11 def api_key @api_key end |
#host ⇒ Object
The host to connect to (defaults to zenboxapp.com).
14 15 16 |
# File 'lib/zenbox/configuration.rb', line 14 def host @host end |
#http_open_timeout ⇒ Object
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_timeout ⇒ Object
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 |
#logger ⇒ Object
The logger used by Zenbox
45 46 47 |
# File 'lib/zenbox/configuration.rb', line 45 def logger @logger end |
#port ⇒ Object
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_host ⇒ Object
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_pass ⇒ Object
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_port ⇒ Object
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_user ⇒ Object
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 |
#secure ⇒ Object 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_chain ⇒ Object 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
62 63 64 |
# File 'lib/zenbox/configuration.rb', line 62 def [](option) send(option) end |
#ca_bundle_path ⇒ Object
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_path ⇒ Object
100 101 102 |
# File 'lib/zenbox/configuration.rb', line 100 def local_cert_path File.(File.join("..", "..", "..", "resources", "ca-bundle.crt"), __FILE__) end |
#merge(hash) ⇒ Object
Returns a hash of all configurable options merged with hash
76 77 78 |
# File 'lib/zenbox/configuration.rb', line 76 def merge(hash) to_hash.merge(hash) end |
#protocol ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/zenbox/configuration.rb', line 84 def protocol if secure? 'https' else 'http' end end |
#to_hash ⇒ Object
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 |