Class: Ksef::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_versionObject

Returns the value of attribute api_version.



18
19
20
# File 'lib/ksef/configuration.rb', line 18

def api_version
  @api_version
end

#base_urlObject

Returns the value of attribute base_url.



18
19
20
# File 'lib/ksef/configuration.rb', line 18

def base_url
  @base_url
end

#environmentObject

Returns the value of attribute environment.



18
19
20
# File 'lib/ksef/configuration.rb', line 18

def environment
  @environment
end

#loggerObject

Returns the value of attribute logger.



18
19
20
# File 'lib/ksef/configuration.rb', line 18

def logger
  @logger
end

#open_timeoutObject

Returns the value of attribute open_timeout.



18
19
20
# File 'lib/ksef/configuration.rb', line 18

def open_timeout
  @open_timeout
end

#timeoutObject

Returns the value of attribute timeout.



18
19
20
# File 'lib/ksef/configuration.rb', line 18

def timeout
  @timeout
end

#user_agentObject

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_urlObject

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