Class: Attio::Comment

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

Overview

Represents a comment in an Attio thread Comments are immutable once created

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

.create(content: nil, format: "plaintext", author: nil, thread_id: nil, created_at: nil, **opts) ⇒ Object

Custom create implementation

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/attio/resources/comment.rb', line 19

def self.create(content: nil, format: "plaintext", author: nil, thread_id: nil, created_at: nil, **opts)
  raise ArgumentError, "Content is required" if content.nil? || content.to_s.empty?
  raise ArgumentError, "Thread ID is required" if thread_id.nil? || thread_id.to_s.empty?
  raise ArgumentError, "Author is required" if author.nil?

  request_params = {
    data: {
      format: format,
      content: content,
      author: author,
      thread_id: thread_id
    }
  }

  # Only add created_at if provided
  request_params[:data][:created_at] = created_at if created_at

  response = execute_request(:POST, resource_path, request_params, opts)
  new(response["data"] || response, opts)
end

.resource_pathString

API endpoint path for comments



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

def self.resource_path
  "comments"
end

Instance Method Details

#destroy(**opts) ⇒ Object

Override destroy to use the correct comment ID



69
70
71
72
73
74
75
76
77
78
# File 'lib/attio/resources/comment.rb', line 69

def destroy(**opts)
  raise InvalidRequestError, "Cannot destroy a comment without an ID" unless persisted?

  comment_id = extract_comment_id
  self.class.send(:execute_request, :DELETE, "#{self.class.resource_path}/#{comment_id}", {}, opts)
  @attributes.clear
  @changed_attributes.clear
  @id = nil
  true
end

#immutable?Boolean

Comments are immutable



59
60
61
# File 'lib/attio/resources/comment.rb', line 59

def immutable?
  true
end

#resolved_atObject

Parse resolved_at as Time



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/attio/resources/comment.rb', line 44

def resolved_at
  value = @attributes[:resolved_at]
  return nil if value.nil?

  case value
  when Time
    value
  when String
    Time.parse(value)
  else
    value
  end
end

#save(**opts) ⇒ Object

Override save to raise error since comments are immutable



64
65
66
# File 'lib/attio/resources/comment.rb', line 64

def save(**opts)
  raise InvalidRequestError, "Comments are immutable and cannot be updated"
end