Sha256: 9ae8f50d81a2347182a24c6e7024933176606847a959df9a72b9893eb98f0577

Contents?: true

Size: 969 Bytes

Versions: 87

Compression:

Stored size: 969 Bytes

Contents

require "net/https"
require "multi_json"

module CFoundry
  module TraceHelpers

    def request_trace(request)
      return nil unless request
      info = ["REQUEST: #{request[:method]} #{request[:url]}"]
      info << "REQUEST_HEADERS:"
      info << header_trace(request[:headers])
      info << "REQUEST_BODY: #{request[:body]}" if request[:body]
      info.join("\n")
    end


    def response_trace(response)
      return nil unless response
      info = ["RESPONSE: [#{response[:status]}]"]
      info << "RESPONSE_HEADERS:"
      info << header_trace(response[:headers])
      info << "RESPONSE_BODY:"
      begin
        parsed_body = MultiJson.load(response[:body])
        info << MultiJson.dump(parsed_body, :pretty => true)
      rescue
        info << "#{response[:body]}"
      end
      info.join("\n")
    end

    private

    def header_trace(headers)
      headers.sort.map do |key, value|
        "  #{key} : #{value}"
      end
    end
  end
end

Version data entries

87 entries across 87 versions & 3 rubygems

Version Path
cloulu-1.0.0 lib/cfoundry/trace_helpers.rb
cloulu-0.7.0 lib/cfoundry/trace_helpers.rb
cloulu-0.6.6 lib/cfoundry/trace_helpers.rb
cloulu-0.6.5 lib/cfoundry/trace_helpers.rb
cloulu-0.6.1 lib/cfoundry/trace_helpers.rb
cloulu-0.6.0 lib/cfoundry/trace_helpers.rb
cloulu-0.5.1 lib/cfoundry/trace_helpers.rb
cloulu-0.5.0 lib/cfoundry/trace_helpers.rb
cloulu-0.3.0 lib/cfoundry/trace_helpers.rb
cloulu-0.2.6 lib/cfoundry/trace_helpers.rb
cloulu-0.2.5 lib/cfoundry/trace_helpers.rb
cloulu-0.2.4 lib/cfoundry/trace_helpers.rb
cloulu-0.2.3 lib/cfoundry/trace_helpers.rb
cloulu-0.2.1 lib/cfoundry/trace_helpers.rb
cloulu-0.2.0 lib/cfoundry/trace_helpers.rb
cloulu-0.1.6 lib/cfoundry/trace_helpers.rb
cloulu-0.1.5 lib/cfoundry/trace_helpers.rb
cloulu-0.1.2 lib/cfoundry/trace_helpers.rb
cloulu-0.1.1 lib/cfoundry/trace_helpers.rb
cfoundry-2.3.5 lib/cfoundry/trace_helpers.rb