Class: Resty::PrettyPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/resty/pretty_printer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, params) ⇒ PrettyPrinter

Returns a new instance of PrettyPrinter.



6
7
8
9
# File 'lib/resty/pretty_printer.rb', line 6

def initialize(options, params)
  @options = options
  @params = params
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/resty/pretty_printer.rb', line 4

def options
  @options
end

#paramsObject

Returns the value of attribute params.



4
5
6
# File 'lib/resty/pretty_printer.rb', line 4

def params
  @params
end

Instance Method Details

#generateObject



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

def generate 
  if params.is_a? Hashie::Mash
    output = ""
    if verbose?
      output += build_line("#{request.method.upcase} #{request.url}")
      request.processed_headers.each { |key, value| output += build_line("#{key}: #{value}") }
      output += "\n"

      output += build_line("Response Code: #{response.code}")
      response.headers.each { |key, value| output += build_line("#{key}: #{value}") }
    else
      output += build_line("Response Code: #{response.code}")
    end

    output += pretty_print_response(response)
  else
    params
  end
end