class ResponseFormatter

Public Class Methods

new(hash) click to toggle source
# File lib/dtracer/response_formatters.rb, line 3
def initialize(hash)
  @hash = hash
  generate
end

Public Instance Methods

body_section(hash) click to toggle source
# File lib/dtracer/response_formatters.rb, line 51
def body_section(hash)
  return nil unless hash["body"]

  ["Body:\n  #{hash["body"]}"]
end
error_section(hash) click to toggle source
# File lib/dtracer/response_formatters.rb, line 57
def error_section(hash)
  return nil unless hash["error"]
  arr = []
  arr << "Error:"
  arr << "  Error Code: #{hash["error"]["errorCode"]}"
  arr << "  Description: #{hash["error"]["localizedDescription"]}"
  arr
end
generate() click to toggle source
# File lib/dtracer/response_formatters.rb, line 8
def generate
  arr = []

  methods = [:response_section, :header_section, :cookie_section, :body_section, :error_section]

  methods.each do |method_name|
    # get content array for a request section
    content_array = self.send(method_name, @hash)
    arr.concat(content_array) if content_array

  end

  @content = arr.join("\n")
end
header_section(hash) click to toggle source
# File lib/dtracer/response_formatters.rb, line 39
def header_section(hash)
  return nil unless hash["headers"]

  hash["headers"].map { |key, value| "  #{key}: #{value}" }.insert(0, "Headers:")
end
response_section(hash) click to toggle source
# File lib/dtracer/response_formatters.rb, line 23
def response_section(hash)
  arr = []

  if hash["statusCode"]
    arr << "Status Code:"
    arr << "  #{hash["statusCode"]}"
  end

  if hash["url"]
    arr << "URL:"
    arr << "  #{hash["url"]}"
  end

  arr
end
to_s() click to toggle source
# File lib/dtracer/response_formatters.rb, line 66
def to_s
  @content
end