Class: TrackUnit::Resource

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/trackunit/resource.rb

Direct Known Subclasses

Unit

Class Method Summary collapse

Class Method Details

.serialize_response(response) ⇒ Object

Raises:



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/trackunit/resource.rb', line 3

def self.serialize_response(response)
  raise TrackUnit::Error if response.blank?
  raise TrackUnit::AuthorizationError.new(response.message) if response.code == 401
  raise TrackUnit::Error.new(response.message) unless response.code == 200

  serialized_data = []
  response.deep_transform_keys(&:underscore)['list'].each do |unit|
    serialized_data << new(unit)
  end
  serialized_data
end