Class: Attio::Object

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

Overview

Represents an object type in Attio (e.g., People, Companies)

Constant Summary

Constants inherited from APIResource

APIResource::SKIP_KEYS

Instance Attribute Summary collapse

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, #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_slugObject (readonly)

Define known attributes



17
18
19
# File 'lib/attio/resources/object.rb', line 17

def api_slug
  @api_slug
end

#created_by_actorObject (readonly)

Define known attributes



17
18
19
# File 'lib/attio/resources/object.rb', line 17

def created_by_actor
  @created_by_actor
end

#plural_nounObject (readonly)

Define known attributes



17
18
19
# File 'lib/attio/resources/object.rb', line 17

def plural_noun
  @plural_noun
end

#singular_nounObject (readonly)

Define known attributes



17
18
19
# File 'lib/attio/resources/object.rb', line 17

def singular_noun
  @singular_noun
end

Class Method Details

.companiesObject

Get the standard Companies object

Returns:

  • (Object)

    The 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

.peopleObject

Get standard objects



76
77
78
# File 'lib/attio/resources/object.rb', line 76

def self.people(**)
  find_by_slug("people", **)
end

.resource_pathString

API endpoint path for objects

Returns:

  • (String)

    The API path



12
13
14
# File 'lib/attio/resources/object.rb', line 12

def self.resource_path
  "objects"
end

Instance Method Details

#attributesObject

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

#create_record(values = {}) ⇒ Object

Create a record for this object



44
45
46
# File 'lib/attio/resources/object.rb', line 44

def create_record(values = {}, **)
  Internal::Record.create(object: api_slug || id, values: values, **)
end

#records(params = {}) ⇒ Object

Get records for this object



39
40
41
# File 'lib/attio/resources/object.rb', line 39

def records(params = {}, **)
  Internal::Record.list(object: api_slug || id, **params, **)
end