@@ -4,9 +4,21 @@ module GetStreamRuby
44
55 class Configuration
66
7- attr_accessor :api_key , :api_secret , :base_url , :timeout , :logger
7+ attr_accessor :api_key , :api_secret , :base_url , :timeout , :logger , :faraday_adapter , :faraday_adapter_options ,
8+ :connection_keep_alive
9+
10+ def initialize ( api_key : nil , api_secret : nil , use_env : true , **options )
11+ base_url = options [ :base_url ]
12+ timeout = options [ :timeout ]
13+ http_options = options [ :http_options ] || { }
14+ faraday_adapter = options [ :faraday_adapter ] || http_options [ :faraday_adapter ]
15+ faraday_adapter_options = options [ :faraday_adapter_options ] || http_options [ :faraday_adapter_options ]
16+ connection_keep_alive = if options . key? ( :connection_keep_alive )
17+ options [ :connection_keep_alive ]
18+ else
19+ http_options [ :connection_keep_alive ]
20+ end
821
9- def initialize ( api_key : nil , api_secret : nil , base_url : nil , timeout : nil , use_env : true )
1022 if use_env
1123 @api_key = api_key || ENV . fetch ( 'STREAM_API_KEY' , nil )
1224 @api_secret = api_secret || ENV . fetch ( 'STREAM_API_SECRET' , nil )
@@ -20,6 +32,13 @@ def initialize(api_key: nil, api_secret: nil, base_url: nil, timeout: nil, use_e
2032 @timeout = timeout || 30
2133 end
2234
35+ @faraday_adapter = ( faraday_adapter || ENV . fetch ( 'STREAM_FARADAY_ADAPTER' , nil ) ) &.to_sym
36+ @faraday_adapter_options = faraday_adapter_options || default_adapter_options
37+ @connection_keep_alive = if connection_keep_alive . nil?
38+ ENV . fetch ( 'STREAM_CONNECTION_KEEP_ALIVE' , 'true' ) == 'true'
39+ else
40+ connection_keep_alive
41+ end
2342 @logger = nil
2443 end
2544
@@ -38,6 +57,9 @@ def dup
3857 api_secret : @api_secret ,
3958 base_url : @base_url ,
4059 timeout : @timeout ,
60+ faraday_adapter : @faraday_adapter ,
61+ faraday_adapter_options : @faraday_adapter_options . dup ,
62+ connection_keep_alive : @connection_keep_alive ,
4163 )
4264 end
4365
@@ -47,9 +69,8 @@ def self.with_overrides(overrides = {})
4769 end
4870
4971 # Method 1: Manual configuration (no environment variables)
50- def self . manual ( api_key :, api_secret :, base_url : nil , timeout : nil )
51- new ( api_key : api_key , api_secret : api_secret ,
52- base_url : base_url , timeout : timeout , use_env : false )
72+ def self . manual ( api_key :, api_secret :, **options )
73+ new ( api_key : api_key , api_secret : api_secret , use_env : false , **options )
5374 end
5475
5576 # Method 2: .env file (loads .env file via dotenv gem, falls back to env vars)
@@ -63,6 +84,12 @@ def self.from_system_env
6384 new ( use_env : true )
6485 end
6586
87+ private
88+
89+ def default_adapter_options
90+ { }
91+ end
92+
6693 end
6794
6895end
0 commit comments