Class: Databasedotcom::Chatter::Conversation

Inherits:
Record
  • Object
show all
Defined in:
lib/databasedotcom/chatter/conversation.rb

Overview

A thread of private messages. When calling Conversation.find or Conversation.all, you must pass :user_id => <my_user_id> in the parameters

Conversation.all(@client, :user_id => "me")
Conversation.find(@client, "conversationId", :user_id => "f80ad89f9d98d89dfd89")

Instance Attribute Summary

Attributes inherited from Record

#client, #id, #name, #raw_hash, #type, #url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Record

all, #delete, delete, find, #parent, #reload, resource_name, search, #user

Constructor Details

#initialize(client, response) ⇒ Conversation

Creates a new Conversation and sets its id and url to values obtained from the server response.



12
13
14
15
16
# File 'lib/databasedotcom/chatter/conversation.rb', line 12

def initialize(client, response)
  super
  @id ||= @raw_hash["conversationId"]
  @url ||= @raw_hash["conversationUrl"]
end

Class Method Details

.archive(client, cid) ⇒ Object

Find the Conversation identified by cid and archive it. Returns the updated Conversation.

Conversation.archive(@client, "fakeid")


21
22
23
24
25
# File 'lib/databasedotcom/chatter/conversation.rb', line 21

def self.archive(client, cid)
  url = "/services/data/v#{client.version}/chatter/users/me/conversations/#{cid}"
  response = client.http_patch(url, nil, :archived => "true")
  Conversation.new(client, response.body)
end

.mark_read(client, cid) ⇒ Object

Find the Conversation identified by cid and mark it as read. Returns the updated Conversation.

Conversation.mark_read(@client, "fakeid")


39
40
41
42
43
# File 'lib/databasedotcom/chatter/conversation.rb', line 39

def self.mark_read(client, cid)
  url = "/services/data/v#{client.version}/chatter/users/me/conversations/#{cid}"
  response = client.http_patch(url, nil, :read => "true")
  Conversation.new(client, response.body)
end

.mark_unread(client, cid) ⇒ Object

Find the Conversation identified by cid and mark it as unread. Returns the updated Conversation.

Conversation.mark_unread(@client, "fakeid")


48
49
50
51
52
# File 'lib/databasedotcom/chatter/conversation.rb', line 48

def self.mark_unread(client, cid)
  url = "/services/data/v#{client.version}/chatter/users/me/conversations/#{cid}"
  response = client.http_patch(url, nil, :read => "false")
  Conversation.new(client, response.body)
end

.messages(client, uid, cid) ⇒ Object

Gets all messages for the Conversation specified by cid and the User specified by uid. Returns a Collection of Message objects.



55
56
57
58
59
60
61
62
# File 'lib/databasedotcom/chatter/conversation.rb', line 55

def self.messages(client, uid, cid)
  conversation = self.find(client, cid, :user_id => uid)
  collection = Databasedotcom::Collection.new(client, nil, conversation.raw_hash["messages"]["nextPageUrl"], conversation.raw_hash["messages"]["previousPageUrl"], conversation.raw_hash["messages"]["currentPageUrl"])
  conversation.raw_hash["messages"]["messages"].each do |item|
    collection << Message.new(client, item)
  end
  collection
end

.unarchive(client, cid) ⇒ Object

Find the Conversation identified by cid and unarchive it. Returns the updated Conversation.

Conversation.unarchive(@client, "fakeid")


30
31
32
33
34
# File 'lib/databasedotcom/chatter/conversation.rb', line 30

def self.unarchive(client, cid)
  url = "/services/data/v#{client.version}/chatter/users/me/conversations/#{cid}"
  response = client.http_patch(url, nil, :archived => "false")
  Conversation.new(client, response.body)
end

Instance Method Details

#archiveObject

Archive this Conversation.



65
66
67
# File 'lib/databasedotcom/chatter/conversation.rb', line 65

def archive
  self.class.archive(self.client, self.id)
end

#mark_readObject

Mark this Conversation as read.



75
76
77
# File 'lib/databasedotcom/chatter/conversation.rb', line 75

def mark_read
  self.class.mark_read(self.client, self.id)
end

#mark_unreadObject

Mark this Conversation as unread.



80
81
82
# File 'lib/databasedotcom/chatter/conversation.rb', line 80

def mark_unread
  self.class.mark_unread(self.client, self.id)
end

#messagesObject

Return a Collection of messages from this Conversation.



85
86
87
88
89
90
91
# File 'lib/databasedotcom/chatter/conversation.rb', line 85

def messages
  collection = Databasedotcom::Collection.new(client, nil, self.raw_hash["messages"]["nextPageUrl"], self.raw_hash["messages"]["previousPageUrl"], self.raw_hash["messages"]["currentPageUrl"])
  self.raw_hash["messages"]["messages"].each do |item|
    collection << Message.new(client, item)
  end
  collection
end

#unarchiveObject

Unarchive this Conversation.



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

def unarchive
  self.class.unarchive(self.client, self.id)
end