Class: Shift::Api::Core::Middleware::Inspector

Inherits:
Faraday::Middleware
  • Object
show all
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

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

Parameters:

  • env (Faraday::Env)

    The environment from faraday



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