Class: ActiveCampaign::Faraday::Middleware::Response
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- ActiveCampaign::Faraday::Middleware::Response
- Includes:
- TransformHash
- Defined in:
- lib/active_campaign/faraday/middleware/response.rb
Overview
Gem specific response middleware for Faraday
Instance Method Summary collapse
- #debug(env) ⇒ Object
- #formatter ⇒ Object
-
#on_complete(env) ⇒ Object
Override this to modify the environment after the response has finished.
- #parse(body) ⇒ Object
-
#transform_key(key, *new_case) ⇒ Symbol
included
from TransformHash
Transform the provided keys case and lastly symbolize it.
-
#transform_keys(hash, *new_case) ⇒ Hash
included
from TransformHash
Transforms case of all hash keys.
-
#transform_value(value, *new_case) ⇒ Object
included
from TransformHash
Transform all values.
Instance Method Details
#debug(env) ⇒ Object
33 34 35 36 |
# File 'lib/active_campaign/faraday/middleware/response.rb', line 33 def debug(env) formatter.request(env) formatter.response(env) end |
#formatter ⇒ Object
38 39 40 41 42 43 |
# File 'lib/active_campaign/faraday/middleware/response.rb', line 38 def formatter @formatter ||= ::Faraday::Logging::Formatter.new( logger: ::Logger.new(STDOUT), options: { headers: true, bodies: true } ) end |
#on_complete(env) ⇒ Object
Override this to modify the environment after the response has finished.
Calls the parse
method if defined
21 22 23 24 |
# File 'lib/active_campaign/faraday/middleware/response.rb', line 21 def on_complete(env) env.body = parse(env.body) debug(env) if ActiveCampaign.config.debug? end |
#parse(body) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/active_campaign/faraday/middleware/response.rb', line 26 def parse(body) return body if body.to_s.empty? body = ::Oj.load(body, mode: :compat) transform_keys(body, :underscore) end |
#transform_key(key, *new_case) ⇒ Symbol Originally defined in module TransformHash
Transform the provided keys case and lastly symbolize it
#transform_keys(hash, *new_case) ⇒ Hash Originally defined in module TransformHash
Note:
this is used to always output a hash response
Transforms case of all hash keys
#transform_value(value, *new_case) ⇒ Object Originally defined in module TransformHash
Note:
used for nested values like hashes and arrays
Transform all values