Module: ActiveCampaignRb::Faraday::Middleware

Defined in:
lib/active_campaign_rb/faraday/middleware.rb,
lib/active_campaign_rb/faraday/middleware/request.rb,
lib/active_campaign_rb/faraday/middleware/response.rb

Overview

Utility functions for managing Faraday middlewares

Author:

Defined Under Namespace

Classes: Request, Response

Class Method Summary collapse

Class Method Details

.add_middleware(faraday, key, options) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/active_campaign_rb/faraday/middleware.rb', line 36

def self.add_middleware(faraday, key, options)
  if options.is_a?(Hash) && options.any?
    faraday.response key, options
  else
    faraday.response key
  end
end

.add_request_middleware(faraday, middleware = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/active_campaign_rb/faraday/middleware.rb', line 14

def self.add_request_middleware(faraday, middleware = {})
  faraday.request :active_campaign, {}

  return if middleware.none?

  middleware.each do |key, options|
    faraday.request key, options unless key.to_s.empty?
  end
end

.add_response_middleware(faraday, middleware = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_campaign_rb/faraday/middleware.rb', line 24

def self.add_response_middleware(faraday, middleware = {})
  faraday.response :active_campaign

  return if middleware.none?

  middleware.each do |key, **options|
    next if key.to_s.empty?

    add_middleware(faraday, key, options)
  end
end