Class: Ksef::Configuration
- Inherits:
-
Object
- Object
- Ksef::Configuration
- Defined in:
- lib/ksef/configuration.rb
Overview
Global gem configuration. Set via ‘Ksef.configure { |c| … }`.
Mutable defaults are exposed so callers can build a per-client ‘Ksef::Client` override without touching the global state.
Constant Summary collapse
- ENVIRONMENTS =
Maps environment symbol → base URL.
{ test: "https://api-test.ksef.mf.gov.pl", demo: "https://api-demo.ksef.mf.gov.pl", production: "https://api.ksef.mf.gov.pl" }.freeze
- DEFAULT_API_VERSION =
"v2"
Instance Attribute Summary collapse
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#resolved_base_url ⇒ Object
Returns the effective base URL for the configured environment, including the ‘/v2` (or whatever) API version path.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
21 22 23 24 25 26 27 28 29 |
# File 'lib/ksef/configuration.rb', line 21 def initialize @environment = :test @user_agent = "ksef-rb/#{Ksef::VERSION}" @timeout = 30 @open_timeout = 10 @api_version = DEFAULT_API_VERSION @base_url = nil @logger = nil end |
Instance Attribute Details
#api_version ⇒ Object
Returns the value of attribute api_version.
18 19 20 |
# File 'lib/ksef/configuration.rb', line 18 def api_version @api_version end |
#base_url ⇒ Object
Returns the value of attribute base_url.
18 19 20 |
# File 'lib/ksef/configuration.rb', line 18 def base_url @base_url end |
#environment ⇒ Object
Returns the value of attribute environment.
18 19 20 |
# File 'lib/ksef/configuration.rb', line 18 def environment @environment end |
#logger ⇒ Object
Returns the value of attribute logger.
18 19 20 |
# File 'lib/ksef/configuration.rb', line 18 def logger @logger end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
18 19 20 |
# File 'lib/ksef/configuration.rb', line 18 def open_timeout @open_timeout end |
#timeout ⇒ Object
Returns the value of attribute timeout.
18 19 20 |
# File 'lib/ksef/configuration.rb', line 18 def timeout @timeout end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
18 19 20 |
# File 'lib/ksef/configuration.rb', line 18 def user_agent @user_agent end |
Instance Method Details
#resolved_base_url ⇒ Object
Returns the effective base URL for the configured environment, including the ‘/v2` (or whatever) API version path.
33 34 35 36 37 38 |
# File 'lib/ksef/configuration.rb', line 33 def resolved_base_url root = @base_url || ENVIRONMENTS.fetch(@environment) do raise ConfigurationError, "Unknown KSeF environment: #{@environment.inspect}" end "#{root.chomp("/")}/#{@api_version}" end |