Sha256: 113614ff255fe4b6a76743cc64997a35d51c5944907ab0a8d025de90dec6bb49

Contents?: true

Size: 468 Bytes

Versions: 3

Compression:

Stored size: 468 Bytes

Contents

require 'faraday'
require 'multi_json'

module MtGox
  module Response
    class ParseJson < Faraday::Response::Middleware

      def parse(body)
        case body
        when /\A^\s*$\z/, nil
          nil
        else
          MultiJson.decode(body)
        end
      end

      def on_complete(env)
        if respond_to?(:parse)
          env[:body] = parse(env[:body]) unless [204, 301, 302, 304].include?(env[:status])
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mtgox-0.9.1 lib/mtgox/response/parse_json.rb
mtgox-0.9.0 lib/mtgox/response/parse_json.rb
mtgox-0.8.2 lib/mtgox/response/parse_json.rb