Module: Spaceborne

Defined in:
lib/spaceborne.rb,
lib/spaceborne/version.rb

Constant Summary collapse

VERSION =
"0.1.10"

Instance Method Summary collapse

Instance Method Details

#is_json?(headers) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/spaceborne.rb', line 8

def is_json?(headers)
  headers.has_key?(:content_type) && headers[:content_type].include?('application/json')
end

#wrap_request(&block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/spaceborne.rb', line 11

def wrap_request(&block)
  block.call
rescue Exception => e
  puts "TIME: #{Time.now.strftime("%d/%m/%Y %H:%M")}"
  puts "REQUEST: #{response.request.method.upcase} #{response.request.url}"
  puts "  HEADERS:\n#{JSON::pretty_generate(response.request.headers)}" 
  puts "  PAYLOAD:\n#{@request_body}" if @request_body
  puts "RESPONSE: #{response.code}"
  puts "  HEADERS:\n#{JSON::pretty_generate(response.headers)}"
  if response.request.method.downcase != 'head'
    if is_json?(response.headers)
      puts "  JSON_BODY\n#{JSON::pretty_generate(json_body)}" 
    else
      puts "  BODY\n#{response.body}"
    end
  end
  raise e
end