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

.digestObject

Returns the value of attribute digest.



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

def digest
  @digest
end

.endpointObject

Returns the value of attribute endpoint.



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

def endpoint
  @endpoint
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.



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

def logger
  @logger
end

.proxyObject

Returns the value of attribute proxy.



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

def proxy
  @proxy
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)


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(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



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

.resetObject



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