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.



14
15
16
# File 'lib/vero/config.rb', line 14

def initialize
  reset!
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#asyncObject

Returns the value of attribute async.



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

def async
  @async
end

#development_modeObject

Returns the value of attribute development_mode.



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

def development_mode
  @development_mode
end

#disabledObject

Returns the value of attribute disabled.



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

def disabled
  @disabled
end

#domainObject



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

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

#loggingObject

Returns the value of attribute logging.



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

def logging
  @logging
end

#secretObject

Returns the value of attribute secret.



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

def secret
  @secret
end

Class Method Details

.available_attributesObject



10
11
12
# File 'lib/vero/config.rb', line 10

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

Instance Method Details

#auth_tokenObject



37
38
39
40
41
# File 'lib/vero/config.rb', line 37

def auth_token
  return unless auth_token?

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

#auth_token?Boolean

Returns:

  • (Boolean)


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

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

#config_paramsObject



18
19
20
# File 'lib/vero/config.rb', line 18

def config_params
  { api_key: api_key, secret: secret }
end

#configured?Boolean

Returns:

  • (Boolean)


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

def configured?
  auth_token?
end

#disable_requests!Object



51
52
53
# File 'lib/vero/config.rb', line 51

def disable_requests!
  self.disabled = true
end

#request_paramsObject



22
23
24
25
26
27
# File 'lib/vero/config.rb', line 22

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

#reset!Object



55
56
57
58
59
60
61
62
# File 'lib/vero/config.rb', line 55

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



64
65
66
67
68
69
70
71
# File 'lib/vero/config.rb', line 64

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

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