Class: Vero::Config

Inherits:
Object show all
Defined in:
lib/vero/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



12
13
14
# File 'lib/vero/config.rb', line 12

def initialize
  self.reset!
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



6
7
8
# File 'lib/vero/config.rb', line 6

def api_key
  @api_key
end

#asyncObject

Returns the value of attribute async.



6
7
8
# File 'lib/vero/config.rb', line 6

def async
  @async
end

#development_modeObject

Returns the value of attribute development_mode.



6
7
8
# File 'lib/vero/config.rb', line 6

def development_mode
  @development_mode
end

#disabledObject

Returns the value of attribute disabled.



6
7
8
# File 'lib/vero/config.rb', line 6

def disabled
  @disabled
end

#domainObject



27
28
29
30
31
32
33
# File 'lib/vero/config.rb', line 27

def domain
  if @domain.blank?
    'https://api.getvero.com'
  else
    @domain =~ /http[s]?\:\/\/.+/ ? @domain : "http://#{@domain}"
  end
end

#loggingObject

Returns the value of attribute logging.



6
7
8
# File 'lib/vero/config.rb', line 6

def logging
  @logging
end

#secretObject

Returns the value of attribute secret.



6
7
8
# File 'lib/vero/config.rb', line 6

def secret
  @secret
end

Class Method Details

.available_attributesObject



8
9
10
# File 'lib/vero/config.rb', line 8

def self.available_attributes
  [:api_key, :secret, :development_mode, :async, :disabled, :logging, :domain]
end

Instance Method Details

#auth_tokenObject



35
36
37
38
# File 'lib/vero/config.rb', line 35

def auth_token
  return unless auth_token?
  ::Base64::encode64("#{api_key}:#{secret}").gsub(/[\n ]/, '')
end

#auth_token?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/vero/config.rb', line 40

def auth_token?
  !api_key.blank? && !secret.blank?
end

#config_paramsObject



16
17
18
# File 'lib/vero/config.rb', line 16

def config_params
  options = {:api_key => self.api_key, :secret => self.secret}
end

#configured?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/vero/config.rb', line 44

def configured?
  auth_token?
end

#disable_requests!Object



48
49
50
# File 'lib/vero/config.rb', line 48

def disable_requests!
  self.disabled = true
end

#request_paramsObject



20
21
22
23
24
25
# File 'lib/vero/config.rb', line 20

def request_params
  {
    :auth_token => self.auth_token,
    :development_mode => self.development_mode
  }.reject { |_, v| v.nil? }
end

#reset!Object



52
53
54
55
56
57
58
59
# File 'lib/vero/config.rb', line 52

def reset!
  self.disabled         = false
  self.development_mode = false
  self.async            = true
  self.logging          = false
  self.api_key          = nil
  self.secret           = nil
end

#update_attributes(attributes = {}) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/vero/config.rb', line 61

def update_attributes(attributes = {})
  return unless attributes.is_a?(Hash)

  Vero::Config.available_attributes.each do |symbol|
    method_name = "#{symbol}=".to_sym
    self.send(method_name, attributes[symbol]) if self.respond_to?(method_name) && attributes.has_key?(symbol)
  end
end