Sha256: 87a6039161dd787f483c5d9c5ce71e9908c73bd4107def177953c7b17a8f914f

Contents?: true

Size: 791 Bytes

Versions: 4

Compression:

Stored size: 791 Bytes

Contents

require 'faraday'
require 'json'
require 'smartsheet/api/faraday_adapter/faraday_response'

module Smartsheet
  module API
    module Middleware
      # Wraps responses into {FaradayResponse FaradayResponses}, parsing JSON bodies when applicable
      class ResponseParser < Faraday::Middleware
        def initialize(app)
          super(app)
        end

        def call(env)
          @app.call(env).on_complete do |response_env|
            if response_env[:response_headers]['content-type'] =~ /\bapplication\/json\b/
              response_env[:body] = JSON.parse(response_env[:body], symbolize_names: true)
            end

            response_env[:body] = FaradayResponse.from_response_env response_env
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
smartsheet-2.77.0 lib/smartsheet/api/faraday_adapter/middleware/response_parser.rb
smartsheet-1.3.0 lib/smartsheet/api/faraday_adapter/middleware/response_parser.rb
smartsheet-1.2.0 lib/smartsheet/api/faraday_adapter/middleware/response_parser.rb
smartsheet-1.1.0 lib/smartsheet/api/faraday_adapter/middleware/response_parser.rb