Class: StraddlePay::Config
- Inherits:
-
Object
- Object
- StraddlePay::Config
- Defined in:
- lib/straddle_pay/config.rb
Overview
Configuration for the StraddlePay client.
Constant Summary collapse
- ENVIRONMENTS =
{ sandbox: "https://sandbox.straddle.com", production: "https://production.straddle.com" }.freeze
Instance Attribute Summary collapse
-
#api_key ⇒ String?
API key for authentication.
-
#base_url ⇒ String
Resolved base URL (custom override or environment-derived).
-
#environment ⇒ Symbol
API environment (:sandbox or :production).
-
#logger ⇒ Logger
Configured logger, falls back to Rails.logger or $stderr.
-
#open_timeout ⇒ Integer
Connection open timeout in seconds (default: 5).
-
#read_timeout ⇒ Integer
Response read timeout in seconds (default: 30).
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
34 35 36 37 38 39 40 41 |
# File 'lib/straddle_pay/config.rb', line 34 def initialize @api_key = ENV.fetch("STRADDLE_API_KEY", nil) @environment = ENV.fetch("STRADDLE_ENVIRONMENT", "sandbox").to_sym @base_url = ENV.fetch("STRADDLE_BASE_URL", nil) @open_timeout = integer_or_default("STRADDLE_OPEN_TIMEOUT", 5) @read_timeout = integer_or_default("STRADDLE_READ_TIMEOUT", 30) validate_environment! end |
Instance Attribute Details
#api_key ⇒ String?
Returns API key for authentication.
21 22 23 |
# File 'lib/straddle_pay/config.rb', line 21 def api_key @api_key end |
#base_url ⇒ String
Returns resolved base URL (custom override or environment-derived).
51 52 53 |
# File 'lib/straddle_pay/config.rb', line 51 def base_url @base_url || ENVIRONMENTS.fetch(@environment) end |
#environment ⇒ Symbol
Returns API environment (:sandbox or :production).
32 33 34 |
# File 'lib/straddle_pay/config.rb', line 32 def environment @environment end |
#logger ⇒ Logger
Returns configured logger, falls back to Rails.logger or $stderr.
56 57 58 |
# File 'lib/straddle_pay/config.rb', line 56 def logger @logger ||= (defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger) || Logger.new($stderr) end |
#open_timeout ⇒ Integer
Returns Connection open timeout in seconds (default: 5).
23 24 25 |
# File 'lib/straddle_pay/config.rb', line 23 def open_timeout @open_timeout end |
#read_timeout ⇒ Integer
Returns Response read timeout in seconds (default: 30).
25 26 27 |
# File 'lib/straddle_pay/config.rb', line 25 def read_timeout @read_timeout end |