Class: Bybit::Configuration
- Inherits:
-
Object
- Object
- Bybit::Configuration
- Defined in:
- lib/bybit/configuration.rb
Constant Summary collapse
- SAFE_ATTRS =
Attributes safe to expose in serialized form. Anything not in this allowlist is dropped from to_json / as_json / marshal_dump — no accidental secret leakage through pino/winston-style default serializers.
%i[testnet base_url recv_window timeout].freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#faraday_connection ⇒ Object
Returns the value of attribute faraday_connection.
-
#recv_window ⇒ Object
Returns the value of attribute recv_window.
-
#testnet ⇒ Object
Returns the value of attribute testnet.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #as_json(*_) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#inspect ⇒ Object
(also: #to_s)
Redact credentials from #inspect and #to_s so a stray puts/logger call doesn't leak the secret into log aggregation.
- #marshal_dump ⇒ Object
-
#marshal_load(hash) ⇒ Object
Un-marshalling a redacted Configuration is intentionally lossy — callers should never round-trip credentials through Marshal.
- #resolved_base_url ⇒ Object
-
#to_h_safe ⇒ Object
Serialization-safe hash used by as_json / to_json / marshal_dump.
- #to_json(*args) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
18 19 20 21 22 |
# File 'lib/bybit/configuration.rb', line 18 def initialize @testnet = false @recv_window = DEFAULT_RECV_WINDOW @timeout = DEFAULT_TIMEOUT end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
15 16 17 |
# File 'lib/bybit/configuration.rb', line 15 def api_key @api_key end |
#api_secret ⇒ Object
Returns the value of attribute api_secret.
15 16 17 |
# File 'lib/bybit/configuration.rb', line 15 def api_secret @api_secret end |
#base_url ⇒ Object
Returns the value of attribute base_url.
15 16 17 |
# File 'lib/bybit/configuration.rb', line 15 def base_url @base_url end |
#faraday_connection ⇒ Object
Returns the value of attribute faraday_connection.
15 16 17 |
# File 'lib/bybit/configuration.rb', line 15 def faraday_connection @faraday_connection end |
#recv_window ⇒ Object
Returns the value of attribute recv_window.
15 16 17 |
# File 'lib/bybit/configuration.rb', line 15 def recv_window @recv_window end |
#testnet ⇒ Object
Returns the value of attribute testnet.
15 16 17 |
# File 'lib/bybit/configuration.rb', line 15 def testnet @testnet end |
#timeout ⇒ Object
Returns the value of attribute timeout.
15 16 17 |
# File 'lib/bybit/configuration.rb', line 15 def timeout @timeout end |
Instance Method Details
#as_json(*_) ⇒ Object
45 46 47 |
# File 'lib/bybit/configuration.rb', line 45 def as_json(*_) to_h_safe.transform_keys(&:to_s) end |
#inspect ⇒ Object Also known as: to_s
Redact credentials from #inspect and #to_s so a stray puts/logger call doesn't leak the secret into log aggregation.
61 62 63 |
# File 'lib/bybit/configuration.rb', line 61 def inspect "#<Bybit::Configuration api_key=#{redact(@api_key)} api_secret=#{redact(@api_secret)} testnet=#{@testnet} base_url=#{resolved_base_url}>" end |
#marshal_dump ⇒ Object
49 50 51 |
# File 'lib/bybit/configuration.rb', line 49 def marshal_dump to_h_safe end |
#marshal_load(hash) ⇒ Object
Un-marshalling a redacted Configuration is intentionally lossy — callers should never round-trip credentials through Marshal.
55 56 57 |
# File 'lib/bybit/configuration.rb', line 55 def marshal_load(hash) hash.each { |k, v| instance_variable_set("@#{k}", v) } end |
#resolved_base_url ⇒ Object
24 25 26 |
# File 'lib/bybit/configuration.rb', line 24 def resolved_base_url base_url || (testnet ? BASE_URL_TESTNET : BASE_URL_MAINNET) end |
#to_h_safe ⇒ Object
Serialization-safe hash used by as_json / to_json / marshal_dump.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bybit/configuration.rb', line 29 def to_h_safe { api_key: redact(@api_key), api_secret: redact(@api_secret), testnet: @testnet, base_url: resolved_base_url, recv_window: @recv_window, timeout: @timeout } end |
#to_json(*args) ⇒ Object
40 41 42 43 |
# File 'lib/bybit/configuration.rb', line 40 def to_json(*args) require 'json' to_h_safe.to_json(*args) end |