Class: Contactually::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/contactually/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, resource) ⇒ Response

Returns a new instance of Response.



11
12
13
14
15
# File 'lib/contactually/response.rb', line 11

def initialize(response, resource)
  @raw_response = response
  @model_type = resource.model
  @interface = resource.interface
end

Instance Attribute Details

#interfaceObject (readonly)

Returns the value of attribute interface.



5
6
7
# File 'lib/contactually/response.rb', line 5

def interface
  @interface
end

#model_typeObject (readonly)

Returns the value of attribute model_type.



5
6
7
# File 'lib/contactually/response.rb', line 5

def model_type
  @model_type
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



5
6
7
# File 'lib/contactually/response.rb', line 5

def raw_response
  @raw_response
end

Instance Method Details

#dataObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/contactually/response.rb', line 17

def data
  @data ||= begin
    if is_a_collection?
      collection = raw_data.map { |item| build_from_model_type(item) }

      Collection.new(collection, meta: meta)
    else
      build_from_model_type(raw_data)
    end
  end
end

#errorsObject



33
34
35
# File 'lib/contactually/response.rb', line 33

def errors
  body.fetch(ERROR_KEY, {})
end

#metaObject



37
38
39
# File 'lib/contactually/response.rb', line 37

def meta
  body.fetch(META_KEY, {})
end

#raw_dataObject



29
30
31
# File 'lib/contactually/response.rb', line 29

def raw_data
  body.fetch(DATA_KEY, {})
end