Class: Intercom::Service::Conversation

Inherits:
BaseService show all
Includes:
ApiOperations::Find, ApiOperations::FindAll, ApiOperations::Load, ApiOperations::Save
Defined in:
lib/intercom/service/conversation.rb

Instance Attribute Summary

Attributes inherited from BaseService

#client

Instance Method Summary collapse

Methods included from ApiOperations::Save

#create, #identity_hash, #save

Methods included from ApiOperations::Load

#load

Methods included from ApiOperations::Find

#find

Methods included from ApiOperations::FindAll

#find_all

Methods inherited from BaseService

#collection_proxy_class, #from_api, #initialize

Constructor Details

This class inherits a constructor from Intercom::Service::BaseService

Instance Method Details

#assign(reply_data) ⇒ Object


39
40
41
42
# File 'lib/intercom/service/conversation.rb', line 39

def assign(reply_data)
  assignee_id = reply_data.fetch(:assignee_id) { fail 'assignee_id is required' }
  reply reply_data.merge(message_type: 'assignment', assignee_id: assignee_id, type: 'admin')
end

#close(reply_data) ⇒ Object


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

def close(reply_data)
  reply reply_data.merge(message_type: 'close', type: 'admin')
end

#collection_classObject


16
17
18
# File 'lib/intercom/service/conversation.rb', line 16

def collection_class
  Intercom::Conversation
end

#mark_read(id) ⇒ Object


20
21
22
# File 'lib/intercom/service/conversation.rb', line 20

def mark_read(id)
  @client.put("/conversations/#{id}", read: true)
end

#open(reply_data) ⇒ Object


31
32
33
# File 'lib/intercom/service/conversation.rb', line 31

def open(reply_data)
  reply reply_data.merge(message_type: 'open', type: 'admin')
end

#reply(reply_data) ⇒ Object


24
25
26
27
28
29
# File 'lib/intercom/service/conversation.rb', line 24

def reply(reply_data)
  id = reply_data.delete(:id)
  collection_name = Utils.resource_class_to_collection_name(collection_class)
  response = @client.post("/#{collection_name}/#{id}/reply", reply_data.merge(:conversation_id => id))
  collection_class.new.from_response(response)
end