Skip to content

Commit

Permalink
Get rid of ivar and use local/param.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Oct 10, 2013
1 parent 040ff09 commit 98f53cf
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/httparty/logger/curl_logger.rb
Expand Up @@ -12,41 +12,41 @@ def initialize(logger, level)

def format(request, response)
@messages = []
@current_time = Time.new.strftime("%Y-%m-%d %H:%M:%S %z")
time = Time.now.strftime("%Y-%m-%d %H:%M:%S %z")
http_method = request.http_method.name.split("::").last.upcase
path = request.path.to_s

print_outgoing "#{http_method} #{path}"
print_outgoing time, "#{http_method} #{path}"
if request.options[:headers] && request.options[:headers].size > 0
request.options[:headers].each do |k, v|
print_outgoing "#{k}: #{v}"
print_outgoing time, "#{k}: #{v}"
end
end

print_outgoing request.raw_body
print_outgoing ""
print_incoming "HTTP/#{response.http_version} #{response.code}"
print_outgoing time, request.raw_body
print_outgoing time, ""
print_incoming time, "HTTP/#{response.http_version} #{response.code}"

headers = response.respond_to?(:headers) ? response.headers : response
response.each_header do |response_header|
print_incoming "#{response_header.capitalize}: #{headers[response_header]}"
print_incoming time, "#{response_header.capitalize}: #{headers[response_header]}"
end

print_incoming "\n#{response.body}"
print_incoming time, "\n#{response.body}"

@logger.send @level, @messages.join("\n")
end

def print_outgoing(line)
@messages << print(">", line)
def print_outgoing(time, line)
@messages << print(time, ">", line)
end

def print_incoming(line)
@messages << print("<", line)
def print_incoming(time, line)
@messages << print(time, "<", line)
end

def print(direction, line)
"[#{TAG_NAME}] [#{@current_time}] #{direction} #{line}"
def print(time, direction, line)
"[#{TAG_NAME}] [#{time}] #{direction} #{line}"
end
end
end
Expand Down

0 comments on commit 98f53cf

Please sign in to comment.