Class: Unit::Resource::BaseResource

Inherits:
Object
  • Object
show all
Defined in:
lib/unit/api_resources/base_resource.rb

Direct Known Subclasses

ApplicationResource, CustomerResource

Class Method Summary collapse

Class Method Details

.response_handler(response) ⇒ Object

Check the response code and return a UnitResponse or UnitError



11
12
13
14
15
16
17
18
19
20
# File 'lib/unit/api_resources/base_resource.rb', line 11

def response_handler(response)
  included = response["included"].nil? ? nil : response["included"]
  meta = response["meta"].nil? ? nil : response["meta"]
  case response.code
  when 200...300
    Unit::UnitResponse.new(response["data"], included, meta)
  else
    Unit::UnitError.from_json_api(response)
  end
end