Class: Rerout::Rails::Configuration
- Inherits:
-
Object
- Object
- Rerout::Rails::Configuration
- Defined in:
- lib/rerout/rails/configuration.rb
Overview
Holds the ‘rerout-rails` configuration and lazily builds a process-wide, cached Client.
Configure it from an initializer (the ‘rerout:install` generator drops one for you):
Rerout::Rails.configure do |config|
config.api_key = ENV.fetch('REROUT_API_KEY')
config.webhook_secret = ENV.fetch('REROUT_WEBHOOK_SECRET')
# config.base_url = 'https://api.rerout.co'
# config.timeout = 30
# config.signature_tolerance_seconds = 300
end
The client is built once on first access and reused — Client wraps a thread-safe Faraday connection, so sharing one instance is the recommended pattern.
Instance Attribute Summary collapse
-
#api_key ⇒ String?
Project API key (‘rrk_…`).
-
#base_url ⇒ String?
Override the API base URL.
-
#signature_tolerance_seconds ⇒ Integer
Webhook signature timestamp tolerance in seconds.
-
#timeout ⇒ Integer
Per-request timeout in seconds.
-
#user_agent ⇒ String?
Override the SDK ‘User-Agent` header.
-
#webhook_path ⇒ String
Path the webhook controller is mounted at when the generated routes are used.
-
#webhook_secret ⇒ String?
Endpoint signing secret (‘whsec_…`).
Instance Method Summary collapse
-
#client ⇒ Rerout::Client
The process-wide cached Client, built from this config.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#reset_client! ⇒ void
Drop the cached client.
-
#webhook_secret! ⇒ String
The configured webhook signing secret.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rerout/rails/configuration.rb', line 50 def initialize @api_key = ENV.fetch('REROUT_API_KEY', nil) @webhook_secret = ENV.fetch('REROUT_WEBHOOK_SECRET', nil) @base_url = ENV.fetch('REROUT_BASE_URL', nil) @timeout = 30 @signature_tolerance_seconds = Rerout::Webhooks::DEFAULT_TOLERANCE_SECONDS @user_agent = nil @webhook_path = '/rerout/webhooks' @client = nil @client_mutex = Mutex.new end |
Instance Attribute Details
#api_key ⇒ String?
Returns project API key (‘rrk_…`). Required before #client can be used.
27 28 29 |
# File 'lib/rerout/rails/configuration.rb', line 27 def api_key @api_key end |
#base_url ⇒ String?
Returns override the API base URL.
34 35 36 |
# File 'lib/rerout/rails/configuration.rb', line 34 def base_url @base_url end |
#signature_tolerance_seconds ⇒ Integer
Returns webhook signature timestamp tolerance in seconds. ‘0` disables the staleness check. Default 300.
41 42 43 |
# File 'lib/rerout/rails/configuration.rb', line 41 def signature_tolerance_seconds @signature_tolerance_seconds end |
#timeout ⇒ Integer
Returns per-request timeout in seconds. Default 30.
37 38 39 |
# File 'lib/rerout/rails/configuration.rb', line 37 def timeout @timeout end |
#user_agent ⇒ String?
Returns override the SDK ‘User-Agent` header.
44 45 46 |
# File 'lib/rerout/rails/configuration.rb', line 44 def user_agent @user_agent end |
#webhook_path ⇒ String
Returns path the webhook controller is mounted at when the generated routes are used. Default ‘/rerout/webhooks`.
48 49 50 |
# File 'lib/rerout/rails/configuration.rb', line 48 def webhook_path @webhook_path end |
#webhook_secret ⇒ String?
Returns endpoint signing secret (‘whsec_…`). Required for webhook signature verification.
31 32 33 |
# File 'lib/rerout/rails/configuration.rb', line 31 def webhook_secret @webhook_secret end |
Instance Method Details
#client ⇒ Rerout::Client
The process-wide cached Client, built from this config.
66 67 68 69 70 71 72 |
# File 'lib/rerout/rails/configuration.rb', line 66 def client return @client if @client @client_mutex.synchronize do @client ||= build_client end end |
#reset_client! ⇒ void
This method returns an undefined value.
Drop the cached client. The next #client call rebuilds it. Useful after changing credentials in tests.
78 79 80 |
# File 'lib/rerout/rails/configuration.rb', line 78 def reset_client! @client_mutex.synchronize { @client = nil } end |
#webhook_secret! ⇒ String
The configured webhook signing secret.
86 87 88 89 90 91 92 93 94 |
# File 'lib/rerout/rails/configuration.rb', line 86 def webhook_secret! if webhook_secret.nil? || webhook_secret.to_s.strip.empty? raise ConfigurationError, 'Rerout::Rails.config.webhook_secret is required to verify ' \ 'webhook signatures. Set it in config/initializers/rerout.rb ' \ 'or via the REROUT_WEBHOOK_SECRET environment variable.' end webhook_secret end |