Class: Restforce::Middleware::JsonResponse

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/restforce/middleware/json_response.rb

Overview

rubocop:disable Style/ClassAndModuleChildren

Constant Summary collapse

CONTENT_TYPE =

This is the only line that differs substantively from the version in Faraday. In Faraday, this refers to a Faraday constant.

'Content-Type'

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of JsonResponse.



22
23
24
25
26
27
28
# File 'lib/restforce/middleware/json_response.rb', line 22

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
end

Instance Method Details

#call(env) ⇒ Object

Taken from ‘lib/faraday/middleware.rb` in the `faraday` gem (<github.com/lostisland/faraday/blob/08b7d4d/lib/faraday/middleware.rb>), with a tiny adaptation to refer to the `@app` instance variable rather than expecting an `attr_reader` to exist.

In Faraday versions before v1.2.0, ‘#call` is missing.

Copyright © 2009-2022 Rick Olson, Zack Hobson Licensed under the MIT License.



41
42
43
44
45
46
# File 'lib/restforce/middleware/json_response.rb', line 41

def call(env)
  on_request(env) if respond_to?(:on_request)
  @app.call(env).on_complete do |environment|
    on_complete(environment) if respond_to?(:on_complete)
  end
end

#on_complete(env) ⇒ Object



48
49
50
# File 'lib/restforce/middleware/json_response.rb', line 48

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