module ActiveCampaignCrm::Client::ContactFields

Contact Fields Interface

Public Instance Methods

add_relationship_to_field(field, rel) click to toggle source
# File lib/active_campaign_crm/client/contact_fields.rb, line 49
def add_relationship_to_field(field, rel)
  response = @connection.post('fieldRels', custom_rel_body(field, rel))
  response['fieldRel']
end
cached_contact_field_id(perstag) click to toggle source
# File lib/active_campaign_crm/client/contact_fields.rb, line 23
def cached_contact_field_id(perstag)
  ActiveCampaignCrm.cache.dig(:contact_fields, perstag)
end
contact_field(id) click to toggle source
# File lib/active_campaign_crm/client/contact_fields.rb, line 10
def contact_field(id)
  response = @connection.get("fields/#{id}")
  response['field']
end
contact_field_body(properties) click to toggle source
# File lib/active_campaign_crm/client/contact_fields.rb, line 62
def contact_field_body(properties)
  { 'field': properties }.to_json
end
contact_fields(params = {}) click to toggle source
# File lib/active_campaign_crm/client/contact_fields.rb, line 5
def contact_fields(params = {})
  response = @connection.get('fields', params)
  response['fields']
end
create_contact_field(properties) click to toggle source
# File lib/active_campaign_crm/client/contact_fields.rb, line 15
def create_contact_field(properties)
  response = @connection.post('fields', contact_field_body(properties))
  field = response['field']
  perstag = field['perstag']
  ActiveCampaignCrm.cache[:contact_fields][perstag] = field['id']
  response['field']
end
custom_rel_body(field, rel) click to toggle source
# File lib/active_campaign_crm/client/contact_fields.rb, line 54
def custom_rel_body(field, rel)
  { 'fieldRel': {
    'field': field,
    'relid': rel
    }
  }.to_json
end
delete_contact_field(id) click to toggle source
# File lib/active_campaign_crm/client/contact_fields.rb, line 71
def delete_contact_field(id)
  response = @connection.delete("fields/#{id}")
end
find_or_create_contact_field(perstag, properties) click to toggle source
# File lib/active_campaign_crm/client/contact_fields.rb, line 27
def find_or_create_contact_field(perstag, properties)
  fields = contact_fields("filters[perstag]": perstag)
  if fields.any?
    ActiveCampaignCrm.cache[:contact_fields][perstag] = fields[0]['id']
    return fields[0]
  end

  create_contact_field(properties)
end
find_or_create_field_with_relationship(perstag, properties, rel) click to toggle source
# File lib/active_campaign_crm/client/contact_fields.rb, line 37
def find_or_create_field_with_relationship(perstag, properties, rel)
  fields = contact_fields("filters[perstag]": perstag)
  if fields.any?
    ActiveCampaignCrm.cache[:contact_fields][perstag] = fields[0]['id']
    return fields[0]
  end

  field = create_contact_field(properties)
  add_relationship_to_field(field['id'], rel)
  field
end
update_contact_field(id, properties) click to toggle source
# File lib/active_campaign_crm/client/contact_fields.rb, line 66
def update_contact_field(id, properties)
  response = @connection.put("fields/#{id}", contact_field_body(properties))
  response['field']
end