Sha256: c98c9e99f0b01d1ed9ff2a7c7ff9fdcf14c327154d279f5610ad0fa8f4b81eb8
Contents?: true
Size: 709 Bytes
Versions: 66
Compression:
Stored size: 709 Bytes
Contents
module JsonApiClient module Middleware class ParseJson < Faraday::Middleware def call(environment) @app.call(environment).on_complete do |env| if process_response_type?(response_type(env)) env[:raw_body] = env[:body] env[:body] = parse(env[:body]) end end end private def parse(body) ::JSON.parse(body) unless body.strip.empty? end def response_type(env) type = env[:response_headers]['Content-Type'].to_s type = type.split(';', 2).first if type.index(';') type end def process_response_type?(type) !!type.match(/\bjson$/) end end end end
Version data entries
66 entries across 66 versions & 2 rubygems