Class: HelpScout::Thread

Inherits:
Base
  • Object
show all
Defined in:
lib/help_scout/thread.rb

Constant Summary collapse

BASIC_ATTRIBUTES =
%i[
  id
  assigned_to
  status
  state
  action
  body
  source
  customer
  created_by
  saved_reply_id
  type
  to
  cc
  bcc
  created_at
  opened_at
  attachments
  conversation_id
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#as_json, #to_h, #to_json

Constructor Details

#initialize(params) ⇒ Thread

Returns a new instance of Thread.



62
63
64
65
66
67
68
69
70
# File 'lib/help_scout/thread.rb', line 62

def initialize(params)
  BASIC_ATTRIBUTES.each do |attribute|
    next unless params[attribute]

    instance_variable_set("@#{attribute}", params[attribute])
  end

  @hrefs = HelpScout::Util.map_links(params.fetch(:_links, []))
end

Instance Attribute Details

#hrefsObject (readonly)

Returns the value of attribute hrefs.



60
61
62
# File 'lib/help_scout/thread.rb', line 60

def hrefs
  @hrefs
end

Class Method Details

.create(conversation_id, thread_type, params) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/help_scout/thread.rb', line 6

def create(conversation_id, thread_type, params)
  HelpScout.api.post(
    create_path(conversation_id, thread_type),
    HelpScout::Util.camelize_keys(params)
  )
  true
end

.get(conversation_id, thread_id) ⇒ Object



20
21
22
23
24
25
# File 'lib/help_scout/thread.rb', line 20

def get(conversation_id, thread_id)
  threads = list(conversation_id)
  thread_id = thread_id.to_i

  threads.find { |thread| thread.id == thread_id }
end

.list(conversation_id, page: nil) ⇒ Object



14
15
16
17
18
# File 'lib/help_scout/thread.rb', line 14

def list(conversation_id, page: nil)
  HelpScout.api.get(
    list_path(conversation_id), page: page
  ).embedded_list.map { |details| new details.merge(conversation_id: conversation_id) }
end

Instance Method Details

#conversationObject



72
73
74
# File 'lib/help_scout/thread.rb', line 72

def conversation
  @_conversation ||= HelpScout::Conversation.get(conversation_id)
end

#update(operation, path, value = nil) ⇒ Object



76
77
78
79
80
# File 'lib/help_scout/thread.rb', line 76

def update(operation, path, value = nil)
  update_path = "conversations/#{conversation_id}/threads/#{id}"
  HelpScout.api.patch(update_path, op: operation, path: path, value: value)
  true
end