Class: Contactually::Response
- Inherits:
-
Object
- Object
- Contactually::Response
- Extended by:
- Forwardable
- Defined in:
- lib/contactually/response.rb
Instance Attribute Summary collapse
-
#interface ⇒ Object
readonly
Returns the value of attribute interface.
-
#model_type ⇒ Object
readonly
Returns the value of attribute model_type.
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
Instance Method Summary collapse
- #data ⇒ Object
- #errors ⇒ Object
-
#initialize(response, resource) ⇒ Response
constructor
A new instance of Response.
- #meta ⇒ Object
- #raw_data ⇒ Object
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
#interface ⇒ Object (readonly)
Returns the value of attribute interface.
5 6 7 |
# File 'lib/contactually/response.rb', line 5 def interface @interface end |
#model_type ⇒ Object (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_response ⇒ Object (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
#data ⇒ Object
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: ) else build_from_model_type(raw_data) end end end |
#errors ⇒ Object
33 34 35 |
# File 'lib/contactually/response.rb', line 33 def errors body.fetch(ERROR_KEY, {}) end |
#meta ⇒ Object
37 38 39 |
# File 'lib/contactually/response.rb', line 37 def body.fetch(META_KEY, {}) end |
#raw_data ⇒ Object
29 30 31 |
# File 'lib/contactually/response.rb', line 29 def raw_data body.fetch(DATA_KEY, {}) end |