Module: WCC::Data::Mapper::JSONResponse

Included in:
WCC::Data::Model
Defined in:
lib/wcc/data/mapper/json_response.rb

Instance Method Summary collapse

Instance Method Details

#new_from_response(response) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/wcc/data/mapper/json_response.rb', line 5

def new_from_response(response)
  raise RecordNotFound if response.status == 404
  raise ServiceUnavailable if response.status == 503
  case response.json
  when Array
    response.json.collect { |obj| new(obj) }
  when Hash
    new(response.json)
  else
    raise InvalidResponse, "Cannot build object from response!"
  end
end