Module: RestApiClient::Response

Included in:
Client
Defined in:
lib/rest_api_client/response.rb

Class Method Summary collapse

Class Method Details

.create(response) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rest_api_client/response.rb', line 4

def self.create(response)
  status = response.status
  case status
  when 200 
    if response.body.present?
      JSON.parse response.body
    else
      response.body
    end
  else
    if response.body.present?
      JSON.parse response.body
    else
      response.body
    end
  end
rescue JSON::ParserError => e
  { "error" => response.body }
end