Class: Koine::RestClient::ResponseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/koine/rest_client/response_parser.rb

Overview

either returns response or raises errors

Instance Method Summary collapse

Instance Method Details

#parse(response) ⇒ Object

Raises:

  • (error_for_code(code))


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/koine/rest_client/response_parser.rb', line 7

def parse(response)
  if block_given?
    yield(response)
  end

  code = Integer(response.code)

  if code.between?(200, 299)
    return response.parsed_response
  end

  raise error_for_code(code), response
end