class CabbageDoc::Response
Attributes
body[R]
code[R]
headers[R]
params[R]
url[R]
Public Class Methods
new(url, params, response)
click to toggle source
# File lib/cabbage_doc/response.rb, line 13 def initialize(url, params, response) @url = url @params = params @headers = convert_headers(response) @code = response.code @body = response.parsed_response end
parse(s, tag = TAG)
click to toggle source
# File lib/cabbage_doc/response.rb, line 8 def parse(s, tag = TAG) YAML.load(s) end
Public Instance Methods
to_json()
click to toggle source
# File lib/cabbage_doc/response.rb, line 25 def to_json { url: highlight(url.join), query: highlight(params.to_query), code: highlight(code.to_s), headers: highlight(prettify(headers), :json), body: highlight(prettify(body), :json) }.to_json end
to_yaml()
click to toggle source
# File lib/cabbage_doc/response.rb, line 21 def to_yaml YAML.dump(self) end
Private Instance Methods
convert_headers(response)
click to toggle source
# File lib/cabbage_doc/response.rb, line 51 def convert_headers(response) {}.tap do |hash| response.headers.each do |k, v| hash[k] = v end end end
highlight(text, type = :sh)
click to toggle source
# File lib/cabbage_doc/response.rb, line 37 def highlight(text, type = :sh) highlighter.format(text, type) end
highlighter()
click to toggle source
# File lib/cabbage_doc/response.rb, line 41 def highlighter @_highlighter ||= Highlighter.new end
prettify(text)
click to toggle source
# File lib/cabbage_doc/response.rb, line 45 def prettify(text) JSON.pretty_generate(text) rescue text.to_s end