Class: Shift::Api::Core::Middleware::Inspector
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Shift::Api::Core::Middleware::Inspector
- Defined in:
- lib/shift/api/core/middleware/inspector.rb
Overview
Faraday middleware to add the ability to register to receive the request environment and/or the response environment from faraday. Useful for recording or even changing requests / responses
Instance Method Summary collapse
-
#call(env) ⇒ Object
Calls the provided handlers before each request and after the response.
-
#initialize(app, before_request_handlers:, after_response_handlers:) ⇒ Inspector
constructor
A new instance of Inspector.
Constructor Details
#initialize(app, before_request_handlers:, after_response_handlers:) ⇒ Inspector
Returns a new instance of Inspector.
11 12 13 14 15 |
# File 'lib/shift/api/core/middleware/inspector.rb', line 11 def initialize(app, before_request_handlers:, after_response_handlers:) self.app = app self.before_request_handlers = before_request_handlers self.after_response_handlers = after_response_handlers end |
Instance Method Details
#call(env) ⇒ Object
Calls the provided handlers before each request and after the response
19 20 21 22 23 24 25 |
# File 'lib/shift/api/core/middleware/inspector.rb', line 19 def call(env) notify_request_handlers(env) request = env.dup app.call(env).on_complete do |env| notify_response_handlers(request, env) end end |