Class: Karotz::Configuration

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



7
8
9
# File 'lib/karotz/configuration.rb', line 7

def api_key
  @api_key
end

.install_idObject

Returns the value of attribute install_id.



7
8
9
# File 'lib/karotz/configuration.rb', line 7

def install_id
  @install_id
end

.loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/karotz/configuration.rb', line 8

def logger
  @logger
end

.secretObject

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

Returns:

  • (Boolean)


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

def blank?(key)
  val = self.send key
  val.nil? || val.empty?
end

.configure(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/karotz/configuration.rb', line 10

def configure(options={})
  init_config
  if block_given?
    yield self
  else
    options.each do |key, value|
      send(:"#{key}=", value)
    end
  end
  self
end

.init_config(force = false) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/karotz/configuration.rb', line 37

def init_config(force=false)
  return if @init && !force
  @init          = true
  @secret        = ''
  @api_key       = ''
  @install_id    = ''
  @logger        = Logger.new(STDERR)
end

.resetObject



26
27
28
# File 'lib/karotz/configuration.rb', line 26

def reset
  init_config(true)
end

.validate_credentials!Object



22
23
24
# File 'lib/karotz/configuration.rb', line 22

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