Class: Equipoise::CustomFields

Inherits:
Object
  • Object
show all
Defined in:
lib/equipoise/custom_fields.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ CustomFields

Returns a new instance of CustomFields.



21
22
23
# File 'lib/equipoise/custom_fields.rb', line 21

def initialize(client)
  @client = client
end

Instance Method Details

#declare(key:, **attributes) ⇒ Object Also known as: upsert

Create-or-update a field by key (server returns 201 vs 200). customizable_type from the body is ignored server-side (defaults to Contact); a client can't declare fields on arbitrary owner types.



38
39
40
# File 'lib/equipoise/custom_fields.rb', line 38

def declare(key:, **attributes)
  @client.request(:post, "/custom_fields", body: { custom_field: { key: key, **attributes }.compact })
end

#delete(key, purge_values: false) ⇒ Object

Returns true on a 204. Pass purge_values: true to delete a field that has values (otherwise the server replies 409).



49
50
51
52
53
# File 'lib/equipoise/custom_fields.rb', line 49

def delete(key, purge_values: false)
  query = purge_values ? { purge_values: true } : {}
  @client.request(:delete, field_path(key), query: query)
  true
end

#get(key, customizable_type: nil) ⇒ Object



30
31
32
33
# File 'lib/equipoise/custom_fields.rb', line 30

def get(key, customizable_type: nil)
  query = { customizable_type: customizable_type }.compact
  @client.request(:get, field_path(key), query: query)
end

#list(customizable_type: nil, page: nil, per_page: nil) ⇒ Object



25
26
27
28
# File 'lib/equipoise/custom_fields.rb', line 25

def list(customizable_type: nil, page: nil, per_page: nil)
  query = { customizable_type: customizable_type, page: page, per_page: per_page }.compact
  @client.request(:get, "/custom_fields", query: query)
end

#update(key, **attributes) ⇒ Object



43
44
45
# File 'lib/equipoise/custom_fields.rb', line 43

def update(key, **attributes)
  @client.request(:patch, field_path(key), body: { custom_field: attributes.compact })
end