Class: Cubscout::Conversation
- Defined in:
- lib/cubscout/conversation.rb
Overview
the Conversation class encapsulates a helpscout conversation.
Instance Attribute Summary
Attributes inherited from Object
Class Method Summary collapse
-
.create_note(id, text:, **attributes) ⇒ Boolean
Create a note to a conversation.
-
.threads(id) ⇒ Array<Object>
Get the threads of a conversation.
-
.update(id, op:, path:, **attributes) ⇒ Object
Update a conversation.
Instance Method Summary collapse
-
#assignee(fetch: false) ⇒ User?
Get the assignee of the conversation.
-
#create_note(attributes) ⇒ Boolean
Create a note to a conversation.
-
#threads(fetch: false) ⇒ Array<Object>
Get the threads of the conversation.
-
#update(attributes) ⇒ Object
Update a conversation.
Methods inherited from Object
Methods included from Scopes
Constructor Details
This class inherits a constructor from Cubscout::Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Cubscout::Object
Class Method Details
.create_note(id, text:, **attributes) ⇒ Boolean
Create a note to a conversation.
34 35 36 |
# File 'lib/cubscout/conversation.rb', line 34 def create_note(id, text:, **attributes) Cubscout.connection.post("#{path}/#{id}/notes", attributes.merge(text: text).to_json).body end |
.threads(id) ⇒ Array<Object>
Get the threads of a conversation. In Helpscout lingo, threads are all the items following a conversation: notes, replies, assignment to users, etc.
11 12 13 |
# File 'lib/cubscout/conversation.rb', line 11 def threads(id) Cubscout.connection.get("#{path}/#{id}/threads").body.dig("_embedded", "threads").map { |item| ThreadItem.new(item) } end |
.update(id, op:, path:, **attributes) ⇒ Object
Update a conversation.
46 47 48 |
# File 'lib/cubscout/conversation.rb', line 46 def update(id, op:, path:, **attributes) Cubscout.connection.patch("#{Conversation.path}/#{id}", attributes.merge(op: op, path: path).to_json).body end |
Instance Method Details
#assignee(fetch: false) ⇒ User?
Get the assignee of the conversation
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cubscout/conversation.rb', line 55 def assignee(fetch: false) return nil unless self.attributes.has_key?("assignee") if fetch User.find(self.attributes.dig("assignee", "id")) else user_attributes = self.attributes.fetch("assignee").merge( "firstName" => self.attributes.dig("assignee", "first"), "lastName" => self.attributes.dig("assignee", "last") ) User.new(user_attributes) end end |
#create_note(attributes) ⇒ Boolean
Create a note to a conversation.
99 100 101 |
# File 'lib/cubscout/conversation.rb', line 99 def create_note(attributes) Conversation.create_note(self.id, attributes) end |
#threads(fetch: false) ⇒ Array<Object>
Get the threads of the conversation. In Helpscout lingo, threads are all the items following a conversation: notes, replies, assignment to users, etc.
76 77 78 79 80 81 82 |
# File 'lib/cubscout/conversation.rb', line 76 def threads(fetch: false) if fetch Conversation.threads(self.id) else self.attributes.dig("_embedded", "threads").map { |item| ThreadItem.new(item) } end end |
#update(attributes) ⇒ Object
Update a conversation.
110 111 112 |
# File 'lib/cubscout/conversation.rb', line 110 def update(attributes) Conversation.update(self.id, attributes) end |