Sha256: a3f50026de420dfae7325fad6159f64235dba86522d7b1bcbb90111868df5e0c

Contents?: true

Size: 551 Bytes

Versions: 5

Compression:

Stored size: 551 Bytes

Contents

require 'faraday'
require 'multi_json'

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

      def parse(body)
          case body
          when ''
            nil
          when 'true'
            true
          when 'false'
            false
          else
            MultiJson.load(body)
          end
      end

      def on_complete(env)
        if respond_to? :parse
          env[:body] = parse(env[:body]) unless env[:request][:raw] or [204,304].index env[:status]
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
capgun-0.2.0 lib/capgun/response/parse_json.rb
capgun-0.1.2 lib/capgun/response/parse_json.rb
capgun-0.1.1 lib/capgun/response/parse_json.rb
capgun-0.1.0 lib/capgun/response/parse_json.rb
capgun-0.0.3 lib/capgun/response/parse_json.rb