class HelpScout::Thread

Constants

BASIC_ATTRIBUTES

Attributes

hrefs[R]

Public Class Methods

create(conversation_id, thread_type, params) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
new(params) click to toggle source
# 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

Private Class Methods

create_path(conversation_id, thread_type) click to toggle source
# File lib/help_scout/thread.rb, line 29
def create_path(conversation_id, thread_type)
  "conversations/#{conversation_id}/#{thread_type}"
end
list_path(conversation_id) click to toggle source
# File lib/help_scout/thread.rb, line 33
def list_path(conversation_id)
  "conversations/#{conversation_id}/threads"
end

Public Instance Methods

conversation() click to toggle source
# File lib/help_scout/thread.rb, line 72
def conversation
  @_conversation ||= HelpScout::Conversation.get(conversation_id)
end
update(operation, path, value = nil) click to toggle source
# 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