Class: EnotasApi::Configuration
- Inherits:
-
Object
- Object
- EnotasApi::Configuration
- 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
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#configured ⇒ Object
readonly
Returns the value of attribute configured.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#request_provider ⇒ Object
readonly
Returns the value of attribute request_provider.
Class Method Summary collapse
Instance Method Summary collapse
- #configure(api_key:, request_provider: RequestProvider.new, base_url: 'https://api.enotasgw.com.br', logger: default_logger) ⇒ Object
- #default_logger ⇒ Object
Instance Attribute Details
#api_key ⇒ Object (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_url ⇒ Object (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 |
#configured ⇒ Object (readonly)
Returns the value of attribute configured.
14 15 16 |
# File 'lib/enotas_api/configuration.rb', line 14 def configured @configured end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
14 15 16 |
# File 'lib/enotas_api/configuration.rb', line 14 def logger @logger end |
#request_provider ⇒ Object (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
.configure ⇒ Object
16 17 18 |
# File 'lib/enotas_api/configuration.rb', line 16 def self.configure(...) instance.configure(...) end |
.current ⇒ Object
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_logger ⇒ Object
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 |