Class: MercadoPublicoCl::Configuration
- Inherits:
-
Object
- Object
- MercadoPublicoCl::Configuration
- Defined in:
- lib/mercado_publico_cl/configuration.rb
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://api.mercadopublico.cl"- DEFAULT_TIMEOUT =
10- DEFAULT_MAX_RETRIES =
0- DEFAULT_RETRY_BASE =
0.5- DEFAULT_RETRY_MAX =
30- DEFAULT_RETRY_ON =
%i[rate_limit server_error timeout].freeze
- LOCAL_HOSTS =
%w[localhost 127.0.0.1 ::1].freeze
- DEFAULT_TIME_ZONE =
"America/Santiago"- FALLBACK_UTC_OFFSET =
Offset de Chile sin TZInfo. Fijo en -04:00 (invierno): en horario de verano el peor caso es pedir el día anterior (con datos), nunca el siguiente (vacío).
"-04:00"
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
-
#retry_base ⇒ Object
Returns the value of attribute retry_base.
-
#retry_max_wait ⇒ Object
Returns the value of attribute retry_max_wait.
-
#retry_on ⇒ Object
Returns the value of attribute retry_on.
-
#ticket ⇒ Object
Returns the value of attribute ticket.
-
#time_zone ⇒ Object
Returns the value of attribute time_zone.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #inspect ⇒ Object (also: #to_s)
- #retry?(category) ⇒ Boolean
- #ticket! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mercado_publico_cl/configuration.rb', line 22 def initialize @ticket = ENV.fetch("MERCADO_PUBLICO_TICKET", nil) @timeout = DEFAULT_TIMEOUT @logger = nil @base_url = DEFAULT_BASE_URL @time_zone = DEFAULT_TIME_ZONE @max_retries = DEFAULT_MAX_RETRIES @retry_base = DEFAULT_RETRY_BASE @retry_max_wait = DEFAULT_RETRY_MAX @retry_on = DEFAULT_RETRY_ON.dup end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
20 21 22 |
# File 'lib/mercado_publico_cl/configuration.rb', line 20 def base_url @base_url end |
#logger ⇒ Object
Returns the value of attribute logger.
18 19 20 |
# File 'lib/mercado_publico_cl/configuration.rb', line 18 def logger @logger end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
18 19 20 |
# File 'lib/mercado_publico_cl/configuration.rb', line 18 def max_retries @max_retries end |
#retry_base ⇒ Object
Returns the value of attribute retry_base.
18 19 20 |
# File 'lib/mercado_publico_cl/configuration.rb', line 18 def retry_base @retry_base end |
#retry_max_wait ⇒ Object
Returns the value of attribute retry_max_wait.
18 19 20 |
# File 'lib/mercado_publico_cl/configuration.rb', line 18 def retry_max_wait @retry_max_wait end |
#retry_on ⇒ Object
Returns the value of attribute retry_on.
20 21 22 |
# File 'lib/mercado_publico_cl/configuration.rb', line 20 def retry_on @retry_on end |
#ticket ⇒ Object
Returns the value of attribute ticket.
18 19 20 |
# File 'lib/mercado_publico_cl/configuration.rb', line 18 def ticket @ticket end |
#time_zone ⇒ Object
Returns the value of attribute time_zone.
18 19 20 |
# File 'lib/mercado_publico_cl/configuration.rb', line 18 def time_zone @time_zone end |
#timeout ⇒ Object
Returns the value of attribute timeout.
18 19 20 |
# File 'lib/mercado_publico_cl/configuration.rb', line 18 def timeout @timeout end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
56 57 58 59 60 61 62 63 |
# File 'lib/mercado_publico_cl/configuration.rb', line 56 def inspect "#<MercadoPublicoCl::Configuration " \ "ticket=#{redacted_ticket} " \ "timeout=#{timeout} " \ "base_url=#{base_url.inspect} " \ "max_retries=#{max_retries} " \ "logger=#{logger.class}>" end |
#retry?(category) ⇒ Boolean
52 53 54 |
# File 'lib/mercado_publico_cl/configuration.rb', line 52 def retry?(category) max_retries.to_i.positive? && retry_on.include?(category) end |
#ticket! ⇒ Object
46 47 48 49 50 |
# File 'lib/mercado_publico_cl/configuration.rb', line 46 def ticket! raise MissingTicketError, "Mercado Público ticket is not configured" if ticket.nil? || ticket.to_s.empty? ticket end |