Class: BodyLogger

Inherits:
Faraday::Response::Logger
  • Object
show all
Defined in:
lib/code42.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



70
71
72
73
# File 'lib/code42.rb', line 70

def call(env)
  debug('response') { dump_body(env[:body]) }
  super
end

#dump_body(body) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/code42.rb', line 80

def dump_body(body)
  if body.respond_to?(:to_str)
    body.to_str
  else
    pretty_inspect(body)
  end
end

#on_complete(env) ⇒ Object



75
76
77
78
# File 'lib/code42.rb', line 75

def on_complete(env)
  debug('response') { dump_body(env[:body]) }
  super
end

#pretty_inspect(body) ⇒ Object



88
89
90
91
# File 'lib/code42.rb', line 88

def pretty_inspect(body)
  require 'pp' unless body.respond_to?(:pretty_inspect)
  body.pretty_inspect
end