Class: YAPI::Response

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/yapi/response.rb

Instance Method Summary collapse

Instance Method Details

#body_strObject



23
24
25
26
27
28
29
# File 'lib/yapi/response.rb', line 23

def body_str
  if self["Content-Type"] =~ /application\/json/
    JSON.pretty_generate(JSON.parse(body)).to_s
  else
    body.to_s
  end
end

#header_strObject



15
16
17
18
19
20
21
# File 'lib/yapi/response.rb', line 15

def header_str
  String.new.tap do |out|
    headers.each do |k, v|
      out << "#{k}: #{v}\n"
    end
  end
end

#to_s(show_headers: true) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/yapi/response.rb', line 7

def to_s(show_headers: true)
  String.new.tap do |out|
    out << "\n#{status}\n\n"
    out << header_str + "\n" if show_headers
    out << body_str
  end
end