Sha256: b3143a62a85733ac5f0fdb785ab3aec0dcefe919ed19dd7962b234db97b9c3c7

Contents?: true

Size: 466 Bytes

Versions: 1

Compression:

Stored size: 466 Bytes

Contents

require 'faraday'
require 'multi_json'

module MLB
  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

1 entries across 1 versions & 1 rubygems

Version Path
mlb-0.6.3 lib/mlb/response/parse_json.rb