Module: CFoundry::TraceHelpers

Included in:
APIError, RestClient
Defined in:
lib/cfoundry/trace_helpers.rb

Instance Method Summary collapse

Instance Method Details

#request_trace(request) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/cfoundry/trace_helpers.rb', line 7

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

#response_trace(response) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cfoundry/trace_helpers.rb', line 17

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