Class: Increase::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ Configuration

TODO: support Faraday config



10
11
12
13
# File 'lib/increase/configuration.rb', line 10

def initialize(config = nil)
  reset
  configure(config) if config
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



6
7
8
# File 'lib/increase/configuration.rb', line 6

def api_key
  @api_key
end

#base_urlObject

Returns the value of attribute base_url.



5
6
7
# File 'lib/increase/configuration.rb', line 5

def base_url
  @base_url
end

#raise_api_errorsObject

Returns the value of attribute raise_api_errors.



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

def raise_api_errors
  @raise_api_errors
end

Instance Method Details

#configure(config = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/increase/configuration.rb', line 21

def configure(config = nil)
  if config.is_a?(Hash)
    config.each do |key, value|
      unless respond_to?("#{key}=")
        raise ArgumentError, "Invalid configuration: #{key}"
      end
      public_send("#{key}=", value)
    end
  end

  if block_given?
    yield self
  end

  self
end

#resetObject



15
16
17
18
19
# File 'lib/increase/configuration.rb', line 15

def reset
  @base_url = ENV["INCREASE_BASE_URL"] || Increase::PRODUCTION_URL
  @api_key = ENV["INCREASE_API_KEY"]
  @raise_api_errors = true
end