Class: Attio::Entry
- Inherits:
-
APIResource
- Object
- APIResource
- Attio::Entry
- Defined in:
- lib/attio/resources/entry.rb
Overview
Represents an entry in an Attio list Entries link records to lists with custom attribute values
Constant Summary
Constants inherited from APIResource
Instance Attribute Summary collapse
-
#entry_values ⇒ Object
Returns the value of attribute entry_values.
-
#list_id ⇒ Object
readonly
Returns the value of attribute list_id.
-
#parent_object ⇒ Object
readonly
Returns the value of attribute parent_object.
-
#parent_record_id ⇒ Object
readonly
Returns the value of attribute parent_record_id.
Attributes inherited from APIResource
Class Method Summary collapse
-
.assert_by_parent(list: nil, parent_record_id: nil, parent_object: nil, entry_values: nil, **opts) ⇒ Object
Assert an entry by parent record.
-
.create(list: nil, parent_record_id: nil, parent_object: nil, entry_values: nil, **opts) ⇒ Object
Create a new entry.
-
.delete(list: nil, entry_id: nil, **opts) ⇒ Object
(also: destroy)
Delete an entry.
-
.list(list: nil, **params) ⇒ Object
(also: all)
List entries for a list.
-
.list_attribute_values(list: nil, entry_id: nil, attribute_id: nil, **opts) ⇒ Object
List attribute values for an entry.
-
.resource_path ⇒ String
API endpoint path for entries (nested under lists).
-
.retrieve(list: nil, entry_id: nil, **opts) ⇒ Object
(also: get, find)
Retrieve a specific entry.
-
.update(list: nil, entry_id: nil, entry_values: nil, mode: nil, **opts) ⇒ Object
Update an entry.
Instance Method Summary collapse
- #destroy(**opts) ⇒ Object
-
#initialize(attributes = {}, opts = {}) ⇒ Entry
constructor
A new instance of Entry.
- #resource_path ⇒ Object
-
#save(**opts) ⇒ Object
Instance methods.
Methods inherited from APIResource
#==, #[], #[]=, api_operations, attr_attio, #changed, #changed?, #changed_attributes, #changes, #each, execute_request, #fetch, #hash, id_param_name, #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
#initialize(attributes = {}, opts = {}) ⇒ Entry
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/attio/resources/entry.rb', line 12 def initialize(attributes = {}, opts = {}) super normalized_attrs = normalize_attributes(attributes) # Extract specific entry attributes @parent_record_id = normalized_attrs[:parent_record_id] @parent_object = normalized_attrs[:parent_object] @entry_values = normalized_attrs[:entry_values] || {} # Extract list_id from nested ID structure if normalized_attrs[:id].is_a?(Hash) @list_id = normalized_attrs[:id][:list_id] end end |
Instance Attribute Details
#entry_values ⇒ Object
Returns the value of attribute entry_values.
10 11 12 |
# File 'lib/attio/resources/entry.rb', line 10 def entry_values @entry_values end |
#list_id ⇒ Object (readonly)
Returns the value of attribute list_id.
9 10 11 |
# File 'lib/attio/resources/entry.rb', line 9 def list_id @list_id end |
#parent_object ⇒ Object (readonly)
Returns the value of attribute parent_object.
9 10 11 |
# File 'lib/attio/resources/entry.rb', line 9 def parent_object @parent_object end |
#parent_record_id ⇒ Object (readonly)
Returns the value of attribute parent_record_id.
9 10 11 |
# File 'lib/attio/resources/entry.rb', line 9 def parent_record_id @parent_record_id end |
Class Method Details
.assert_by_parent(list: nil, parent_record_id: nil, parent_object: nil, entry_values: nil, **opts) ⇒ Object
Assert an entry by parent record
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/attio/resources/entry.rb', line 103 def assert_by_parent(list: nil, parent_record_id: nil, parent_object: nil, entry_values: nil, **opts) validate_list_identifier!(list) validate_parent_params!(parent_record_id, parent_object) request_params = { data: { parent_record_id: parent_record_id, parent_object: parent_object, entry_values: entry_values || {} } } response = execute_request(:PUT, "#{resource_path}/#{list}/entries", request_params, opts) new(response["data"] || response, opts) end |
.create(list: nil, parent_record_id: nil, parent_object: nil, entry_values: nil, **opts) ⇒ Object
Create a new entry
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/attio/resources/entry.rb', line 45 def create(list: nil, parent_record_id: nil, parent_object: nil, entry_values: nil, **opts) validate_list_identifier!(list) validate_parent_params!(parent_record_id, parent_object) request_params = { data: { parent_record_id: parent_record_id, parent_object: parent_object, entry_values: entry_values || {} } } response = execute_request(:POST, "#{resource_path}/#{list}/entries", request_params, opts) new(response["data"] || response, opts) end |
.delete(list: nil, entry_id: nil, **opts) ⇒ Object Also known as: destroy
Delete an entry
93 94 95 96 97 98 99 |
# File 'lib/attio/resources/entry.rb', line 93 def delete(list: nil, entry_id: nil, **opts) validate_list_identifier!(list) validate_entry_id!(entry_id) execute_request(:DELETE, "#{resource_path}/#{list}/entries/#{entry_id}", {}, opts) true end |
.list(list: nil, **params) ⇒ Object Also known as: all
List entries for a list
36 37 38 39 40 41 |
# File 'lib/attio/resources/entry.rb', line 36 def list(list: nil, **params) validate_list_identifier!(list) response = execute_request(:POST, "#{resource_path}/#{list}/entries/query", params, {}) APIResource::ListObject.new(response, self, params.merge(list: list), params) end |
.list_attribute_values(list: nil, entry_id: nil, attribute_id: nil, **opts) ⇒ Object
List attribute values for an entry
120 121 122 123 124 125 126 127 |
# File 'lib/attio/resources/entry.rb', line 120 def list_attribute_values(list: nil, entry_id: nil, attribute_id: nil, **opts) validate_list_identifier!(list) validate_entry_id!(entry_id) raise ArgumentError, "Attribute ID is required" if attribute_id.nil? || attribute_id.to_s.empty? response = execute_request(:GET, "#{resource_path}/#{list}/entries/#{entry_id}/attributes/#{attribute_id}/values", {}, opts) response["data"] || [] end |
.resource_path ⇒ String
API endpoint path for entries (nested under lists)
31 32 33 |
# File 'lib/attio/resources/entry.rb', line 31 def resource_path "lists" end |
.retrieve(list: nil, entry_id: nil, **opts) ⇒ Object Also known as: get, find
Retrieve a specific entry
62 63 64 65 66 67 68 |
# File 'lib/attio/resources/entry.rb', line 62 def retrieve(list: nil, entry_id: nil, **opts) validate_list_identifier!(list) validate_entry_id!(entry_id) response = execute_request(:GET, "#{resource_path}/#{list}/entries/#{entry_id}", {}, opts) new(response["data"] || response, opts) end |
.update(list: nil, entry_id: nil, entry_values: nil, mode: nil, **opts) ⇒ Object
Update an entry
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/attio/resources/entry.rb', line 73 def update(list: nil, entry_id: nil, entry_values: nil, mode: nil, **opts) validate_list_identifier!(list) validate_entry_id!(entry_id) request_params = { data: { entry_values: entry_values || {} } } # Add mode parameter for append operations if mode == "append" request_params[:mode] = "append" end response = execute_request(:PATCH, "#{resource_path}/#{list}/entries/#{entry_id}", request_params, opts) new(response["data"] || response, opts) end |
Instance Method Details
#destroy(**opts) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/attio/resources/entry.rb', line 165 def destroy(**opts) raise InvalidRequestError, "Cannot destroy an entry without an ID" unless persisted? raise InvalidRequestError, "Cannot destroy without list context" unless list_id entry_id = extract_entry_id self.class.send(:execute_request, :DELETE, "lists/#{list_id}/entries/#{entry_id}", {}, opts) @attributes.clear @changed_attributes.clear @id = nil true end |
#resource_path ⇒ Object
177 178 179 180 181 |
# File 'lib/attio/resources/entry.rb', line 177 def resource_path raise InvalidRequestError, "Cannot generate path without list context" unless list_id entry_id = extract_entry_id "lists/#{list_id}/entries/#{entry_id}" end |
#save(**opts) ⇒ Object
Instance methods
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/attio/resources/entry.rb', line 148 def save(**opts) raise InvalidRequestError, "Cannot save an entry without an ID" unless persisted? raise InvalidRequestError, "Cannot save without list context" unless list_id # For Entry, we always save the full entry_values params = { data: { entry_values: entry_values } } response = self.class.send(:execute_request, :PATCH, resource_path, params, opts) update_from(response[:data] || response) reset_changes! self end |