Class: Attio::Object
- Inherits:
-
APIResource
- Object
- APIResource
- Attio::Object
- Defined in:
- lib/attio/resources/object.rb
Overview
Represents an object type in Attio (e.g., People, Companies)
Constant Summary
Constants inherited from APIResource
Instance Attribute Summary collapse
-
#api_slug ⇒ Object
readonly
Define known attributes.
-
#created_by_actor ⇒ Object
readonly
Define known attributes.
-
#plural_noun ⇒ Object
readonly
Define known attributes.
-
#singular_noun ⇒ Object
readonly
Define known attributes.
Attributes inherited from APIResource
Class Method Summary collapse
-
.companies ⇒ Object
Get the standard Companies object.
-
.find_by(**conditions) ⇒ Object
Find by attribute using Rails-style syntax.
-
.find_by_slug(slug, **opts) ⇒ Object
Find by API slug (deprecated - use find_by(slug: ...) instead).
-
.people ⇒ Object
Get standard objects.
-
.resource_path ⇒ String
API endpoint path for objects.
Instance Method Summary collapse
-
#attributes ⇒ Object
Get all attributes for this object.
-
#create_attribute(params = {}) ⇒ Object
Create a new attribute for this object.
-
#create_record(values = {}) ⇒ Object
Create a record for this object.
-
#initialize(attributes = {}, opts = {}) ⇒ Object
constructor
A new instance of Object.
-
#records(params = {}) ⇒ Object
Get records for this object.
Methods inherited from APIResource
#==, #[], #[]=, api_operations, attr_attio, #changed, #changed?, #changed_attributes, #changes, #destroy, #each, execute_request, #fetch, #hash, id_param_name, #inspect, #key?, #keys, #persisted?, prepare_params_for_create, prepare_params_for_update, #reset_changes!, resource_name, #resource_path, #revert!, #save, #to_h, #to_json, #update_attributes, #update_from, validate_id!, #values
Constructor Details
#initialize(attributes = {}, opts = {}) ⇒ Object
Returns a new instance of Object.
19 20 21 22 23 24 25 26 |
# File 'lib/attio/resources/object.rb', line 19 def initialize(attributes = {}, opts = {}) super normalized_attrs = normalize_attributes(attributes) @api_slug = normalized_attrs[:api_slug] @singular_noun = normalized_attrs[:singular_noun] @plural_noun = normalized_attrs[:plural_noun] @created_by_actor = normalized_attrs[:created_by_actor] end |
Instance Attribute Details
#api_slug ⇒ Object (readonly)
Define known attributes
17 18 19 |
# File 'lib/attio/resources/object.rb', line 17 def api_slug @api_slug end |
#created_by_actor ⇒ Object (readonly)
Define known attributes
17 18 19 |
# File 'lib/attio/resources/object.rb', line 17 def created_by_actor @created_by_actor end |
#plural_noun ⇒ Object (readonly)
Define known attributes
17 18 19 |
# File 'lib/attio/resources/object.rb', line 17 def plural_noun @plural_noun end |
#singular_noun ⇒ Object (readonly)
Define known attributes
17 18 19 |
# File 'lib/attio/resources/object.rb', line 17 def singular_noun @singular_noun end |
Class Method Details
.companies ⇒ Object
Get the standard Companies object
82 83 84 |
# File 'lib/attio/resources/object.rb', line 82 def self.companies(**) find_by_slug("companies", **) end |
.find_by(**conditions) ⇒ Object
Find by attribute using Rails-style syntax
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/attio/resources/object.rb', line 49 def self.find_by(**conditions) # Extract any opts that aren't conditions opts = {} known_opts = [:api_key, :timeout, :idempotency_key] known_opts.each do |opt| opts[opt] = conditions.delete(opt) if conditions.key?(opt) end # Currently only supports slug if conditions.key?(:slug) slug = conditions[:slug] begin retrieve(slug, **opts) rescue NotFoundError list(**opts).find { |obj| obj.api_slug == slug } end else raise ArgumentError, "find_by only supports slug attribute for objects" end end |
.find_by_slug(slug, **opts) ⇒ Object
Find by API slug (deprecated - use find_by(slug: ...) instead)
71 72 73 |
# File 'lib/attio/resources/object.rb', line 71 def self.find_by_slug(slug, **opts) find_by(slug: slug, **opts) end |
.people ⇒ Object
Get standard objects
76 77 78 |
# File 'lib/attio/resources/object.rb', line 76 def self.people(**) find_by_slug("people", **) end |
.resource_path ⇒ String
API endpoint path for objects
12 13 14 |
# File 'lib/attio/resources/object.rb', line 12 def self.resource_path "objects" end |
Instance Method Details
#attributes ⇒ Object
Get all attributes for this object
29 30 31 |
# File 'lib/attio/resources/object.rb', line 29 def attributes(**) Attribute.list(parent_object: api_slug || id, **) end |
#create_attribute(params = {}) ⇒ Object
Create a new attribute for this object
34 35 36 |
# File 'lib/attio/resources/object.rb', line 34 def create_attribute(params = {}, **) Attribute.create(params.merge(parent_object: api_slug || id), **) end |