class LogMe::HttpFormatter

Public Instance Methods

format_request(request, url) click to toggle source
# File lib/logme/http_formatter.rb, line 4
def format_request(request, url)
  message = format_message(request) do
    message =  with_line_break { 'Request:' }
    message << with_line_break { "#{request.method.to_s.upcase} #{url}" }
  end
end
format_response(response) click to toggle source
# File lib/logme/http_formatter.rb, line 11
def format_response(response)
  message = format_message(response) do
    message =  with_line_break { 'Response:' }
    message << with_line_break { "HTTP/#{response.http_version} #{response.code} #{response.message}" }
  end
end

Private Instance Methods

blank?(text) click to toggle source
# File lib/logme/http_formatter.rb, line 37
def blank?(text)
  text.to_s.strip.empty?
end
extract_body_from(http) click to toggle source
# File lib/logme/http_formatter.rb, line 31
def extract_body_from(http)
  return http.body if http.respond_to?(:body)
  return http.args[:payload] if http.respond_to?(:args)
  return nil
end
format_message(http) { || ... } click to toggle source
# File lib/logme/http_formatter.rb, line 20
def format_message(http)
  message = yield
  body = extract_body_from(http)
  message << with_line_break { body } unless blank?(body)
  message
end
with_line_break() click to toggle source
# File lib/logme/http_formatter.rb, line 27
def with_line_break
  "#{yield}\n"
end