Class: Faraday::Response::Json

Inherits:
Middleware show all
Defined in:
lib/faraday/response/json.rb

Overview

Parse response bodies as JSON.

Instance Attribute Summary

Attributes inherited from Middleware

#app, #options

Instance Method Summary collapse

Methods inherited from Middleware

#call, #close

Methods included from MiddlewareRegistry

#lookup_middleware, #register_middleware, #registered_middleware, #unregister_middleware

Constructor Details

#initialize(app = nil, parser_options: nil, content_type: /\bjson$/, preserve_raw: false) ⇒ Json

Returns a new instance of Json.



9
10
11
12
13
14
15
16
# File 'lib/faraday/response/json.rb', line 9

def initialize(app = nil, parser_options: nil, content_type: /\bjson$/, preserve_raw: false)
  super(app)
  @parser_options = parser_options
  @content_types = Array(content_type)
  @preserve_raw = preserve_raw

  process_parser_options
end

Instance Method Details

#on_complete(env) ⇒ Object



18
19
20
# File 'lib/faraday/response/json.rb', line 18

def on_complete(env)
  process_response(env) if parse_response?(env)
end