Class: Faraday::Rashify::Middleware

Inherits:
Middleware
  • Object
show all
Defined in:
lib/faraday/rashify.rb

Overview

This is a middleware which acts on responses, so it implements ‘on_complete`.

Constant Summary collapse

CONTENT_TYPE =
'Content-Type'

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, options = {}) ⇒ Middleware

Public: Converts parsed response bodies to a Hashie::Mash::Rash if they were of Hash or Array type.



17
18
19
20
21
# File 'lib/faraday/rashify.rb', line 17

def initialize(app = nil, options = {})
  super(app)
  @options = options
  @content_types = Array(options[:content_type])
end

Instance Method Details

#on_complete(env) ⇒ Object



23
24
25
26
27
28
# File 'lib/faraday/rashify.rb', line 23

def on_complete(env)
  # return early if we should not process this request
  return unless should_process?(env)

  env[:body] = parse(env[:body])
end