Sha256: f9c71d317ff68e8a3de940a6ca046cac206ddd9f09c4b1346512a8ecf3eefc53

Contents?: true

Size: 868 Bytes

Versions: 2

Compression:

Stored size: 868 Bytes

Contents

# frozen_string_literal: true

# For faraday_middleware/response_middleware.
# https://github.com/r7kamura/weneedfeed/issues/19
require 'active_support'
require 'active_support/isolated_execution_state' if ActiveSupport.gem_version >= Gem::Version.new('7')

require 'active_support/core_ext/array/conversions'
require 'active_support/core_ext/hash/conversions'
require 'faraday'
require 'faraday_middleware/response_middleware'
require 'json'

module Weneedfeed
  class FaradayResponseMiddleware < ::FaradayMiddleware::ResponseMiddleware
    define_parser do |body, options|
      options ||= {}
      options = { dasherize: false }.merge(options)
      object = ::JSON.parse(body)
      object.to_xml(options)
    end

    # @note Overriding.
    def parse_response?(env)
      env.response.headers['Content-Type'].to_s.include?('application/json')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
weneedfeed-0.11.0 lib/weneedfeed/faraday_response_middleware.rb
weneedfeed-0.10.0 lib/weneedfeed/faraday_response_middleware.rb