Class: Belpost::Configuration
- Inherits:
-
Object
- Object
- Belpost::Configuration
- 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
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#jwt_token ⇒ Object
Returns the value of attribute jwt_token.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#to_h ⇒ Hash
Returns a hash representation of the configuration.
-
#validate! ⇒ Object
Validates that all required configuration is present.
Constructor Details
#initialize ⇒ Configuration
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_url ⇒ Object
Returns the value of attribute base_url.
7 8 9 |
# File 'lib/belpost/configuration.rb', line 7 def base_url @base_url end |
#jwt_token ⇒ Object
Returns the value of attribute jwt_token.
7 8 9 |
# File 'lib/belpost/configuration.rb', line 7 def jwt_token @jwt_token end |
#timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/belpost/configuration.rb', line 7 def timeout @timeout end |
Instance Method Details
#to_h ⇒ Hash
Returns a hash representation of the configuration
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
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 |