Class: MyTargetApi::ResponseFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/my_target_api/response_formatter.rb

Overview

Format response

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ResponseFormatter

Returns a new instance of ResponseFormatter.



9
10
11
# File 'lib/my_target_api/response_formatter.rb', line 9

def initialize(response)
  @response = response
end

Instance Method Details

#formatObject



13
14
15
16
17
18
19
20
21
# File 'lib/my_target_api/response_formatter.rb', line 13

def format
  headers = response.headers.empty? ? ' No headers' : "\n#{headers_in_lines}"
  body = response.body.to_s == '' ? ' No body' : "\n#{response.body}"
  <<~RESPONSE
    HTTP Code: #{response.code}
    HTTP Body:#{body}
    HTTP Headers:#{headers}
  RESPONSE
end