Class: HelpScout::Conversation

Inherits:
Base
  • Object
show all
Extended by:
Getable, Listable
Defined in:
lib/help_scout/conversation.rb

Constant Summary collapse

BASIC_ATTRIBUTES =
%i[
  id
  number
  type
  folder_id
  status
  state
  subject
  preview
  mailbox_id
  assignee
  created_by
  created_at
  closed_by
  closed_at
  user_updated_at
  customer_waiting_since
  source
  tags
  cc
  bcc
  primary_customer
  custom_fields
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Getable

get

Methods included from Listable

list, list_path

Methods inherited from Base

#as_json, #to_h, #to_json

Constructor Details

#initialize(params) ⇒ Conversation

Returns a new instance of Conversation.



53
54
55
56
57
58
59
60
61
# File 'lib/help_scout/conversation.rb', line 53

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.



51
52
53
# File 'lib/help_scout/conversation.rb', line 51

def hrefs
  @hrefs
end

Class Method Details

.create(params) ⇒ Object



9
10
11
12
# File 'lib/help_scout/conversation.rb', line 9

def create(params)
  response = HelpScout.api.post(create_path, HelpScout::Util.camelize_keys(params))
  response.location
end

Instance Method Details

#populated_threadsObject



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

def populated_threads
  @_populated_threads ||= HelpScout::Thread.list(id)
end

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



67
68
69
70
71
# File 'lib/help_scout/conversation.rb', line 67

def update(operation, path, value = nil)
  update_path = URI.parse(hrefs[:self]).path
  HelpScout.api.patch(update_path, op: operation, path: path, value: value)
  true
end

#update_tags(new_tags = nil) ⇒ Object



73
74
75
76
77
78
# File 'lib/help_scout/conversation.rb', line 73

def update_tags(new_tags = nil)
  new_tags ||= []
  tags_path = URI.parse(hrefs[:self]).path + '/tags'
  HelpScout.api.put(tags_path, tags: new_tags)
  true
end