Class: PetstoreApiClient::Middleware::Authentication
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- PetstoreApiClient::Middleware::Authentication
- Defined in:
- lib/petstore_api_client/middleware/authentication.rb
Overview
Faraday middleware for authentication Applies authentication strategy to each request
This middleware follows the Interceptor pattern - it intercepts outgoing requests and adds authentication headers before they’re sent
This is the same pattern used by industry-standard gems:
-
Octokit (GitHub API)
-
Slack-ruby-client
-
Stripe Ruby
Instance Method Summary collapse
-
#call(env) ⇒ Faraday::Response
Process request - apply authentication before sending.
-
#initialize(app, options = {}) ⇒ Authentication
constructor
Initialize middleware with authentication strategy.
Constructor Details
#initialize(app, options = {}) ⇒ Authentication
Initialize middleware with authentication strategy
26 27 28 29 |
# File 'lib/petstore_api_client/middleware/authentication.rb', line 26 def initialize(app, = {}) super(app) @authenticator = [:authenticator] end |
Instance Method Details
#call(env) ⇒ Faraday::Response
Process request - apply authentication before sending
35 36 37 38 39 40 41 |
# File 'lib/petstore_api_client/middleware/authentication.rb', line 35 def call(env) # Apply authentication if configured @authenticator&.apply(env) if @authenticator&.configured? # Continue to next middleware @app.call(env) end |