Class: Attio::Thread

Inherits:
APIResource show all
Defined in:
lib/attio/resources/thread.rb

Overview

Represents a comment thread in Attio (read-only)

Constant Summary

Constants inherited from APIResource

APIResource::SKIP_KEYS

Instance Attribute Summary

Attributes inherited from APIResource

#created_at, #id, #metadata

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from APIResource

#==, #[], #[]=, api_operations, attr_attio, #changed, #changed?, #changed_attributes, #changes, #each, execute_request, #fetch, #hash, id_param_name, #initialize, #key?, #keys, #persisted?, prepare_params_for_create, prepare_params_for_update, #reset_changes!, resource_name, #revert!, #to_json, #update_attributes, #update_from, validate_id!, #values

Constructor Details

This class inherits a constructor from Attio::APIResource

Class Method Details

.list(**params) ⇒ Object Also known as: all

Custom list implementation to handle query params properly



19
20
21
22
23
24
25
26
# File 'lib/attio/resources/thread.rb', line 19

def self.list(**params)
  # Query params should be part of the request, not opts
  query_params = params.slice(:record_id, :object, :entry_id, :list, :limit, :offset)
  opts = params.except(:record_id, :object, :entry_id, :list, :limit, :offset)

  response = execute_request(:GET, resource_path, query_params, opts)
  ListObject.new(response, self, params, opts)
end

.resource_pathString

API endpoint path for threads

Returns:

  • (String)

    The API path



14
15
16
# File 'lib/attio/resources/thread.rb', line 14

def self.resource_path
  "threads"
end

Instance Method Details

#comment_countObject

Helper methods for working with comments



36
37
38
# File 'lib/attio/resources/thread.rb', line 36

def comment_count
  comments&.length || 0
end

#destroy(**opts) ⇒ Object

Override destroy to raise error since threads are read-only



67
68
69
# File 'lib/attio/resources/thread.rb', line 67

def destroy(**opts)
  raise InvalidRequestError, "Threads are read-only and cannot be deleted"
end

#first_commentHash?

Get the first comment in the thread

Returns:

  • (Hash, nil)

    First comment or nil if empty



46
47
48
# File 'lib/attio/resources/thread.rb', line 46

def first_comment
  comments&.first
end

#has_comments?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/attio/resources/thread.rb', line 40

def has_comments?
  comment_count > 0
end

#immutable?Boolean

Threads are read-only

Returns:

  • (Boolean)


57
58
59
# File 'lib/attio/resources/thread.rb', line 57

def immutable?
  true
end

#last_commentHash?

Get the last comment in the thread

Returns:

  • (Hash, nil)

    Last comment or nil if empty



52
53
54
# File 'lib/attio/resources/thread.rb', line 52

def last_comment
  comments&.last
end

#save(**opts) ⇒ Object

Override save to raise error since threads are read-only



62
63
64
# File 'lib/attio/resources/thread.rb', line 62

def save(**opts)
  raise InvalidRequestError, "Threads are read-only and cannot be modified"
end