Class: Layer::Conversation

Overview

Note:

This is available in both the REST and the Platform API. Please refer to the respective documentation to see which methods are available.

Examples:

Creating a new conversation

conversation = Layer::Conversation.create({ participants: ['1', '2'] })

Finding an existing conversation

conversation = Layer::Conversation.find('CONVERSATION_ID_HERE')

Updating an existing conversation

conversation = Layer::Conversation.find('CONVERSATION_ID_HERE')
conversation.participants << 3
conversation.[:foo] = 'bar'
conversation.save

See Also:

Instance Attribute Summary

Attributes inherited from Resource

#attributes, #client

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Operations::Delete::ClassMethods

delete

Methods included from Operations::Create::ClassMethods

create

Methods included from Operations::Paginate::ClassMethods

all

Methods included from Operations::Find::ClassMethods

find

Methods included from Operations::Patch

#attributes=, #save

Methods included from Operations::Delete

#delete

Methods included from Operations::Find

#reload

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

.destroy(id, client = self.client) ⇒ Object

Note:

This is only available via the REST API.

Destroys the conversation with the given id for all participants


33
34
35
36
# File 'lib/layer/conversation.rb', line 33

def self.destroy(id, client = self.client)
  id = Layer::Client.normalize_id(id)
  client.delete("#{url}/#{id}", {}, { params: { destroy: true } })
end

Instance Method Details

#created_atTime

Returns the time the conversation was created at


70
71
72
# File 'lib/layer/conversation.rb', line 70

def created_at
  Time.parse(attributes['created_at'])
end

#destroyObject

Note:

This is only available via the REST API.

Destroys the conversation for all participants


77
78
79
# File 'lib/layer/conversation.rb', line 77

def destroy
  client.delete(url, {}, { params: { destroy: true } })
end

#distinct?Boolean

Whether the conversation is distinct


63
64
65
# File 'lib/layer/conversation.rb', line 63

def distinct?
  attributes['distinct']
end

#messagesLayer::RelationProxy

Note:

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 converations messages


42
43
44
# File 'lib/layer/conversation.rb', line 42

def messages
  RelationProxy.new(self, Message, [Operations::Create, Operations::Paginate, Operations::Find])
end

#metadataLayer::Patch::Hash

Returns the conversations metadata


49
50
51
# File 'lib/layer/conversation.rb', line 49

def 
  attributes['metadata'] ||= {}
end

#participantsLayer::Patch::Array

Returns the conversations metadata


56
57
58
# File 'lib/layer/conversation.rb', line 56

def participants
  attributes['participants'] ||= []
end