Class: Intercom::Lib::TypedJsonDeserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/intercom/lib/typed_json_deserializer.rb

Overview

Responsibility: To decide whether we are deserializing a collection or an entity of a particular type and to dispatch deserialization

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, client, type = nil) ⇒ TypedJsonDeserializer

Returns a new instance of TypedJsonDeserializer.



12
13
14
15
16
# File 'lib/intercom/lib/typed_json_deserializer.rb', line 12

def initialize(json, client, type = nil)
  @json = json
  @client = client
  @type = type
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



10
11
12
# File 'lib/intercom/lib/typed_json_deserializer.rb', line 10

def json
  @json
end

Instance Method Details

#deserializeObject



18
19
20
21
22
23
24
25
26
# File 'lib/intercom/lib/typed_json_deserializer.rb', line 18

def deserialize
  if blank_object_type?(object_type)
    raise DeserializationError, 'No type field was found to facilitate deserialization'
  elsif list_object_type?(object_type)
    deserialize_collection(json[object_entity_key])
  else # singular object type
    deserialize_object(json)
  end
end