require 'faraday_middleware/response_middleware'
require 'faraday_middleware/request/encode_json'

module FaradayMiddleware
  module MultiJson
    class ParseJson < FaradayMiddleware::ResponseMiddleware
      dependency 'multi_json'

      def parse(body)
        ::MultiJson.load(body, @options) rescue body
      end
    end

    class EncodeJson < FaradayMiddleware::EncodeJson
      dependency 'multi_json'

      def initialize(app, *)
        super(app)
      end

      def encode(data)
        ::MultiJson.dump data
      end
    end
  end
end

Faraday.register_middleware :response, :multi_json => FaradayMiddleware::MultiJson::ParseJson
Faraday.register_middleware :request, :multi_json => FaradayMiddleware::MultiJson::EncodeJson

require 'faraday_middleware/response_middleware'
require 'faraday_middleware/request/encode_json'

module FaradayMiddleware
  module MultiJson
    class ParseJson < FaradayMiddleware::ResponseMiddleware
      dependency 'multi_json'

      def parse(body)
        ::MultiJson.load(body, @options) rescue body
      end
    end

    class EncodeJson < FaradayMiddleware::EncodeJson
      dependency 'multi_json'

      def initialize(app, *)
        super(app)
      end

      def encode(data)
        ::MultiJson.dump data
      end
    end
  end
end

Faraday::Response.register_middleware :multi_json => FaradayMiddleware::MultiJson::ParseJson
Faraday::Request.register_middleware :multi_json => FaradayMiddleware::MultiJson::EncodeJson

Update middleware registry for Faraday 0.9
Update middleware registry for Faraday 0.9

The unified method `Faraday.register_middleware` for registering all
kinds of middleware was gone in 0.9.

https://github.com/lostisland/faraday/commit/14b458a9c971897f44d5ee3ba5354de52c998e72
