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

Instance Method Summary collapse

Methods included from Operations::Find::ClassMethods

find

Methods included from Operations::Paginate::ClassMethods

all

Methods included from Operations::Create::ClassMethods

create

Methods included from Operations::Delete::ClassMethods

delete

Methods included from Operations::Destroy::ClassMethods

destroy

Methods included from Operations::Patch

#attributes=, #save

Methods included from Operations::Destroy

#destroy

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

Instance Method Details

#contentsLayer::RelationProxy

Note:

This is only available via the Platform API.

Allows creating and finding of the conversation’s rich content

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/layer/conversation.rb', line 43

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_atTime

Returns the time the conversation was created at

Returns:

  • (Time)

    the time the conversation was created at



86
87
88
# File 'lib/layer/conversation.rb', line 86

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

#distinct?Boolean

Whether the conversation is distinct

Returns:

  • (Boolean)

    whether the conversation is distinct



79
80
81
# File 'lib/layer/conversation.rb', line 79

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

Returns:

See Also:



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

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

#metadataLayer::Patch::Hash

Returns the conversations metadata

Returns:



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

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

#participantsLayer::Patch::Array

Returns the conversations metadata

Returns:



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

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