Class: Belpost::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/belpost/configuration.rb

Overview

Class for managing the Belpochta API configuration. Allows you to set basic parameters such as API URL, JWT token, and request timeout.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/belpost/configuration.rb', line 9

def initialize
  @base_url = ENV.fetch("BELPOST_API_URL", "https://api.belpost.by")
  @jwt_token = ENV.fetch("BELPOST_JWT_TOKEN", nil)

  # Convert timeout to integer with a fallback to default
  begin
    @timeout = Integer(ENV.fetch("BELPOST_TIMEOUT", 10))
  rescue ArgumentError
    @timeout = 10
  end
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



7
8
9
# File 'lib/belpost/configuration.rb', line 7

def base_url
  @base_url
end

#jwt_tokenObject

Returns the value of attribute jwt_token.



7
8
9
# File 'lib/belpost/configuration.rb', line 7

def jwt_token
  @jwt_token
end

#timeoutObject

Returns the value of attribute timeout.



7
8
9
# File 'lib/belpost/configuration.rb', line 7

def timeout
  @timeout
end

Instance Method Details

#to_hHash

Returns a hash representation of the configuration

Returns:

  • (Hash)

    The configuration as a hash



30
31
32
33
34
35
36
# File 'lib/belpost/configuration.rb', line 30

def to_h
  {
    base_url: base_url,
    jwt_token: jwt_token,
    timeout: timeout
  }
end

#validate!Object

Validates that all required configuration is present

Raises:



23
24
25
26
# File 'lib/belpost/configuration.rb', line 23

def validate!
  raise ConfigurationError, "Base URL is required" if base_url.nil?
  raise ConfigurationError, "JWT token is required" if jwt_token.nil?
end