Class: Layer::Conversation
- Extended by:
- Operations::Create::ClassMethods, Operations::Find::ClassMethods, Operations::Paginate::ClassMethods
- Includes:
- Operations::Create, Operations::Delete, Operations::Destroy, Operations::Find, Operations::Paginate, Operations::Patch
- Defined in:
- lib/layer/conversation.rb
Overview
This is available in both the REST and the Platform API. Please refer to the respective documentation to see which methods are available.
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
-
.delete(id, options = {}, client = self.client) ⇒ Object
Deletes the resource with the given id.
-
.destroy(id, client = self.client) ⇒ Object
Destroys the resource with the given id.
Instance Method Summary collapse
-
#contents ⇒ Layer::RelationProxy
Allows creating and finding of the conversation’s rich content.
-
#created_at ⇒ Time
Returns the time the conversation was created at.
-
#delete(options = {}) ⇒ Object
Deletes the conversation, removing it from the user’s devices by default.
-
#destroy ⇒ Object
Destroys the conversation, removing it for everyone.
-
#distinct? ⇒ Boolean
Whether the conversation is distinct.
-
#messages ⇒ Layer::RelationProxy
Returns the conversations messages.
-
#metadata ⇒ Layer::Patch::Hash
Returns the conversations metadata.
-
#participants ⇒ Layer::Patch::Array
Returns the conversations metadata.
Methods included from Operations::Find::ClassMethods
Methods included from Operations::Paginate::ClassMethods
Methods included from Operations::Create::ClassMethods
Methods included from Operations::Patch
Methods included from Operations::Find
Methods inherited from Resource
class_name, from_response, #id, #initialize, #respond_to_missing?, url, #url
Constructor Details
This class inherits a constructor from Layer::Resource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Layer::Resource
Class Method Details
.delete(id, options = {}, client = self.client) ⇒ Object
Deletes the resource with the given id
In the REST API, this deletes the conversation for the current user only
37 38 39 40 41 |
# File 'lib/layer/conversation.rb', line 37 def self.delete(id, = {}, client = self.client) id = Layer::Client.normalize_id(id) = { mode: :my_devices }.merge() client.delete("#{url}/#{id}", {}, { params: }) end |
.destroy(id, client = self.client) ⇒ Object
Destroys the resource with the given id
In the REST API, this deletes the conversation for everyone
50 51 52 |
# File 'lib/layer/conversation.rb', line 50 def self.destroy(id, client = self.client) delete(id, { mode: :all_participants }, client) end |
Instance Method Details
#contents ⇒ Layer::RelationProxy
This is only available via the Platform API.
Allows creating and finding of the conversation’s rich content
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/layer/conversation.rb', line 66 def contents RelationProxy.new(self, Content, [Operations::Create, Operations::Find]) do def create(mime_type, file, client = self.client) response = client.post(url, {}, { 'Upload-Content-Type' => mime_type, 'Upload-Content-Length' => file.size }) attributes = response.merge('size' => file.size, 'mime_type' => mime_type) Content.from_response(attributes, client).tap do |content| content.upload(file) end end end end |
#created_at ⇒ Time
Returns the time the conversation was created at
109 110 111 |
# File 'lib/layer/conversation.rb', line 109 def created_at Time.parse(attributes['created_at']) end |
#delete(options = {}) ⇒ Object
Deletes the conversation, removing it from the user’s devices by default
124 125 126 127 |
# File 'lib/layer/conversation.rb', line 124 def delete( = {}) = { mode: :my_devices }.merge() client.delete(url, {}, { params: }) end |
#destroy ⇒ Object
Destroys the conversation, removing it for everyone
116 117 118 |
# File 'lib/layer/conversation.rb', line 116 def destroy delete(mode: :all_participants) end |
#distinct? ⇒ Boolean
Whether the conversation is distinct
102 103 104 |
# File 'lib/layer/conversation.rb', line 102 def distinct? attributes['distinct'] end |
#messages ⇒ Layer::RelationProxy
This is available in both the REST and the Platform API. Please refer to the respective documentation to see which methods are available.
Returns the conversations messages
58 59 60 |
# File 'lib/layer/conversation.rb', line 58 def RelationProxy.new(self, Message, [Operations::Create, Operations::Paginate, Operations::Find, Operations::Delete, Operations::Destroy]) end |
#metadata ⇒ Layer::Patch::Hash
Returns the conversations metadata
86 87 88 89 |
# File 'lib/layer/conversation.rb', line 86 def attributes['metadata'] ||= {} attributes['metadata'] end |
#participants ⇒ Layer::Patch::Array
Returns the conversations metadata
94 95 96 97 |
# File 'lib/layer/conversation.rb', line 94 def participants attributes['participants'] ||= [] attributes['participants'] end |