Class: UniRateRails::Configuration
- Inherits:
-
Object
- Object
- UniRateRails::Configuration
- Defined in:
- lib/unirate_rails/configuration.rb
Overview
Process-wide configuration, populated in an initializer via
configure. The API key falls back to the UNIRATE_API_KEY
environment variable so a secret never has to be committed to the host app.
# config/initializers/unirate.rb
UniRateRails.configure do |c|
c.api_key = ENV.fetch("UNIRATE_API_KEY")
c.default_currency = "USD"
c.enable_historical = false
end
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://api.unirateapi.com"- DEFAULT_TIMEOUT =
30
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Resolves from the explicit setter first, then the environment.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#default_currency ⇒ Object
Returns the value of attribute default_currency.
-
#enable_historical ⇒ Object
Returns the value of attribute enable_historical.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/unirate_rails/configuration.rb', line 21 def initialize @api_key = nil @base_url = DEFAULT_BASE_URL @timeout = DEFAULT_TIMEOUT @default_currency = "USD" # Historical endpoints are Pro-gated (HTTP 403 on the free tier). Off by # default so a free-tier app never surfaces a confusing 403; flip it on # once the account has a Pro subscription. @enable_historical = false end |
Instance Attribute Details
#api_key ⇒ Object
Resolves from the explicit setter first, then the environment.
33 34 35 36 37 |
# File 'lib/unirate_rails/configuration.rb', line 33 def api_key return @api_key unless @api_key.nil? || @api_key.to_s.empty? ENV.fetch("UNIRATE_API_KEY", nil) end |
#base_url ⇒ Object
Returns the value of attribute base_url.
18 19 20 |
# File 'lib/unirate_rails/configuration.rb', line 18 def base_url @base_url end |
#default_currency ⇒ Object
Returns the value of attribute default_currency.
18 19 20 |
# File 'lib/unirate_rails/configuration.rb', line 18 def default_currency @default_currency end |
#enable_historical ⇒ Object
Returns the value of attribute enable_historical.
18 19 20 |
# File 'lib/unirate_rails/configuration.rb', line 18 def enable_historical @enable_historical end |
#timeout ⇒ Object
Returns the value of attribute timeout.
18 19 20 |
# File 'lib/unirate_rails/configuration.rb', line 18 def timeout @timeout end |