Class: Pluggy::Configuration
- Inherits:
-
Object
- Object
- Pluggy::Configuration
- Defined in:
- lib/pluggy/configuration.rb
Constant Summary collapse
- DEFAULTS =
{ api_base: "https://api.pluggy.ai", client_id: nil, client_secret: nil, # A pre-existing apiKey. Disables automatic renewal: there are no # credentials to renew with, so an expiry raises AuthenticationError. api_key: nil, open_timeout: 30, # Generous because GET /accounts/{id}/balance proxies to the financial # institution in real time -- it is the one endpoint in scope that # documents both a 429 and a 502. read_timeout: 80, write_timeout: 30, max_network_retries: 2, initial_network_retry_delay: 0.5, max_network_retry_delay: 4.0, logger: nil, log_level: :info, # Parse JSON numbers as BigDecimal. Turning this off yields plain Floats # and makes the gem dependency-free. decimal_amounts: true, coerce_times: true, user_agent_suffix: nil, verify_ssl_certs: true, # :v2 (cursor, current) or :v1 (offset, deprecated, sunset 2026-12-31). transactions_api_version: :v2 }.freeze
- LOG_LEVELS =
{ debug: 0, info: 1, error: 2 }.freeze
- SECRET_OPTIONS =
%i[client_secret api_key].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#connection_key ⇒ Object
Net::HTTP pool key: two configs pointing at the same endpoint share a connection.
- #credentials? ⇒ Boolean
-
#initialize(**overrides) ⇒ Configuration
constructor
A new instance of Configuration.
-
#inspect ⇒ Object
(also: #to_s)
Never leak secrets into a log, a console session or an exception.
- #log(level, message, **context) ⇒ Object
-
#merge(**overrides) ⇒ Object
Per-client options win over the globals they were merged from, but only where explicitly given -- Stripe's reverse_duplicate_merge.
- #uri ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(**overrides) ⇒ Configuration
Returns a new instance of Configuration.
45 46 47 48 |
# File 'lib/pluggy/configuration.rb', line 45 def initialize(**overrides) DEFAULTS.each { |key, value| instance_variable_set(:"@#{key}", value) } apply(overrides) end |
Class Method Details
.setup ⇒ Object
41 42 43 |
# File 'lib/pluggy/configuration.rb', line 41 def self.setup new.tap { |config| yield config if block_given? } end |
Instance Method Details
#connection_key ⇒ Object
Net::HTTP pool key: two configs pointing at the same endpoint share a connection.
62 63 64 |
# File 'lib/pluggy/configuration.rb', line 62 def connection_key [uri.host, uri.port, verify_ssl_certs] end |
#credentials? ⇒ Boolean
66 67 68 |
# File 'lib/pluggy/configuration.rb', line 66 def credentials? !(client_id.nil? || client_secret.nil?) end |
#inspect ⇒ Object Also known as: to_s
Never leak secrets into a log, a console session or an exception.
87 88 89 90 91 92 93 94 |
# File 'lib/pluggy/configuration.rb', line 87 def inspect shown = DEFAULTS.keys.map do |key| value = public_send(key) value = redact(value) if SECRET_OPTIONS.include?(key) "#{key}=#{value.inspect}" end "#<Pluggy::Configuration #{shown.join(" ")}>" end |
#log(level, message, **context) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/pluggy/configuration.rb', line 78 def log(level, , **context) return unless logger return unless LOG_LEVELS.fetch(level, 1) >= LOG_LEVELS.fetch(log_level, 1) suffix = context.map { |k, v| "#{k}=#{v}" }.join(" ") logger.public_send(level, "[pluggy] #{}#{" #{suffix}" unless suffix.empty?}") end |
#merge(**overrides) ⇒ Object
Per-client options win over the globals they were merged from, but only where explicitly given -- Stripe's reverse_duplicate_merge.
52 53 54 |
# File 'lib/pluggy/configuration.rb', line 52 def merge(**overrides) dup.tap { |config| config.send(:apply, overrides.compact) } end |
#uri ⇒ Object
56 57 58 |
# File 'lib/pluggy/configuration.rb', line 56 def uri @uri ||= URI.parse(api_base) end |
#validate! ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/pluggy/configuration.rb', line 70 def validate! return if credentials? || api_key raise ConfigurationError, "provide client_id: and client_secret: (or api_key:) to Pluggy::Client.new, " \ "or set Pluggy.client_id / Pluggy.client_secret" end |