Class: Karotz::Configuration
- Inherits:
-
Object
- Object
- Karotz::Configuration
- Defined in:
- lib/karotz/configuration.rb
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.digest ⇒ Object
Returns the value of attribute digest.
-
.endpoint ⇒ Object
Returns the value of attribute endpoint.
-
.install_id ⇒ Object
Returns the value of attribute install_id.
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.proxy ⇒ Object
Returns the value of attribute proxy.
-
.secret ⇒ Object
Returns the value of attribute secret.
Class Method Summary collapse
- .blank?(key) ⇒ Boolean
- .configure(options = {}) ⇒ Object
- .init_config(force = false) ⇒ Object
- .reset ⇒ Object
- .validate_credentials! ⇒ Object
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/karotz/configuration.rb', line 7 def api_key @api_key end |
.digest ⇒ Object
Returns the value of attribute digest.
9 10 11 |
# File 'lib/karotz/configuration.rb', line 9 def digest @digest end |
.endpoint ⇒ Object
Returns the value of attribute endpoint.
8 9 10 |
# File 'lib/karotz/configuration.rb', line 8 def endpoint @endpoint end |
.install_id ⇒ Object
Returns the value of attribute install_id.
7 8 9 |
# File 'lib/karotz/configuration.rb', line 7 def install_id @install_id end |
.logger ⇒ Object
Returns the value of attribute logger.
9 10 11 |
# File 'lib/karotz/configuration.rb', line 9 def logger @logger end |
.proxy ⇒ Object
Returns the value of attribute proxy.
8 9 10 |
# File 'lib/karotz/configuration.rb', line 8 def proxy @proxy end |
.secret ⇒ Object
Returns the value of attribute secret.
7 8 9 |
# File 'lib/karotz/configuration.rb', line 7 def secret @secret end |
Class Method Details
.blank?(key) ⇒ Boolean
31 32 33 34 |
# File 'lib/karotz/configuration.rb', line 31 def blank?(key) val = self.send key val.nil? || val.empty? end |
.configure(options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/karotz/configuration.rb', line 11 def configure(={}) init_config if block_given? yield self else .each do |key, value| send(:"#{key}=", value) end end self end |
.init_config(force = false) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/karotz/configuration.rb', line 38 def init_config(force=false) return if @init && !force @init = true @secret = '' @api_key = '' @install_id = '' @proxy = nil @logger = Logger.new(STDERR) @endpoint = "http://api.karotz.com/api/karotz/" @digest = OpenSSL::Digest::Digest.new('sha1') end |
.reset ⇒ Object
27 28 29 |
# File 'lib/karotz/configuration.rb', line 27 def reset init_config(true) end |
.validate_credentials! ⇒ Object
23 24 25 |
# File 'lib/karotz/configuration.rb', line 23 def validate_credentials! raise "you have to configure Karotz: 'configure :install_id => 'your-install-id', :api_key => 'your-api-key', :secret => 'your-secret'" if blank?(:api_key) || blank?(:secret) || blank?(:install_id) end |