Module: ApiClient::Parser

Defined in:
lib/api-client/parser.rb

Overview

ApiClient::Parser provides a method to parse the request response.

Class Method Summary collapse

Class Method Details

.response(response, url) ⇒ Hash

Parse the JSON response.

Parameters:

  • response (HTTP)

    HTTP object for the request.

  • url (String)

    The url of the requisition.

Returns:

  • (Hash)

    the body parsed.


10
11
12
13
14
15
16
17
18
# File 'lib/api-client/parser.rb', line 10

def self.response(response, url)
  raise_exception(response, url)
  begin
    object = ::JSON.parse(response.body)
  rescue ::JSON::ParserError, TypeError
    object = {}
  end
  object
end