Sha256: d5d4471c54e800ac93f410cf43e5f19117ba275664a944a7aaaf7a59ed2d6179

Contents?: true

Size: 499 Bytes

Versions: 5

Compression:

Stored size: 499 Bytes

Contents

require 'faraday'
require 'multi_json'

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

      def parse(body)
        case body
        when /\A^\s*$\z/, nil
          nil
        else
          MultiJson.decode(body, :symbolize_keys => true)
        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

5 entries across 5 versions & 1 rubygems

Version Path
fantasydata-0.2.2 lib/fantasydata/response/parse_json.rb
fantasydata-0.2.1 lib/fantasydata/response/parse_json.rb
fantasydata-0.2.0 lib/fantasydata/response/parse_json.rb
fantasydata-0.0.2 lib/fantasydata/response/parse_json.rb
fantasydata-0.0.1 lib/fantasydata/response/parse_json.rb