Class: EnotasApi::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/enotas_api/configuration.rb

Constant Summary collapse

NO_CONFIGURATION_ERROR =
'It\'s necessary to configure EnotasApi before to call any API method \n' \
'Please configure using EnotasApi::Configuration.configure(api_key: \'your api key\')'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



14
15
16
# File 'lib/enotas_api/configuration.rb', line 14

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



14
15
16
# File 'lib/enotas_api/configuration.rb', line 14

def base_url
  @base_url
end

#configuredObject (readonly)

Returns the value of attribute configured.



14
15
16
# File 'lib/enotas_api/configuration.rb', line 14

def configured
  @configured
end

#loggerObject (readonly)

Returns the value of attribute logger.



14
15
16
# File 'lib/enotas_api/configuration.rb', line 14

def logger
  @logger
end

#request_providerObject (readonly)

Returns the value of attribute request_provider.



14
15
16
# File 'lib/enotas_api/configuration.rb', line 14

def request_provider
  @request_provider
end

Class Method Details

.configureObject



16
17
18
# File 'lib/enotas_api/configuration.rb', line 16

def self.configure(...)
  instance.configure(...)
end

.currentObject

Raises:



20
21
22
23
24
# File 'lib/enotas_api/configuration.rb', line 20

def self.current
  raise EnotasApi::Error, NO_CONFIGURATION_ERROR unless instance.configured

  instance
end

Instance Method Details

#configure(api_key:, request_provider: RequestProvider.new, base_url: 'https://api.enotasgw.com.br', logger: default_logger) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/enotas_api/configuration.rb', line 26

def configure(
  api_key:,
  request_provider: RequestProvider.new,
  base_url: 'https://api.enotasgw.com.br',
  logger: default_logger
)
  @configured = true
  @api_key = api_key
  @request_provider = request_provider
  @base_url = base_url
  @logger = logger
end

#default_loggerObject



39
40
41
42
43
44
45
# File 'lib/enotas_api/configuration.rb', line 39

def default_logger
  logger = Logger.new($stdout)
  logger.formatter = proc do |severity, datetime, _progname, msg|
    "#{datetime} #{severity}: #{msg}\n"
  end
  logger
end