Class: RestAPIBuilder::RestClientResponseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rest_api_builder/rest_client_response_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger:, parse_json:, raw_response:) ⇒ RestClientResponseParser

Returns a new instance of RestClientResponseParser.



5
6
7
8
9
# File 'lib/rest_api_builder/rest_client_response_parser.rb', line 5

def initialize(logger:, parse_json:, raw_response:)
  @logger = logger
  @parse_json = parse_json
  @raw_response = raw_response
end

Instance Method Details

#parse_response(response, success:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rest_api_builder/rest_client_response_parser.rb', line 11

def parse_response(response, success:)
  return { success: success, raw_response: response } if @raw_response

  body = @parse_json ? parse_json(response.body) : response.body

  result = {
    success: success,
    status: response.code,
    body: body,
    headers: response.headers
  }
  maybe_log_result(result)

  result
end