module ActiveCampaignCrm::Client::Tags

Tag Interface

Public Instance Methods

add_tag_to_contact(contact, tag) click to toggle source
# File lib/active_campaign_crm/client/tags.rb, line 37
def add_tag_to_contact(contact, tag)
  response = @connection.post('contactTags',
                              contact_link_tag_body(contact, tag))
  response['contactTag']
end
cached_tag_id(tag) click to toggle source
# File lib/active_campaign_crm/client/tags.rb, line 22
def cached_tag_id(tag)
  ActiveCampaignCrm.cache.dig(:tags, tag)
end
create_tag(fields) click to toggle source
# File lib/active_campaign_crm/client/tags.rb, line 15
def create_tag(fields)
  response = @connection.post('tags', tag_body(fields))
  tag_name = response['tag']['tag']
  ActiveCampaignCrm.cache[:tags][tag_name] = response['tag']['id']
  response['tag']
end
delete_tag(id) click to toggle source
# File lib/active_campaign_crm/client/tags.rb, line 48
def delete_tag(id)
  @connection.delete("tags/#{id}")
end
sync_tag(tag, type, description) click to toggle source
# File lib/active_campaign_crm/client/tags.rb, line 26
def sync_tag(tag, type, description)
  query = { 'filters[tag]': tag }
  tags = tags(query)
  if tags.any?
    ActiveCampaignCrm.cache[:tags][tag] = tags[0]['id']
    return tags[0]
  end

  create_tag(tag: tag, tagType: type, description: description)
end
tag(id) click to toggle source
# File lib/active_campaign_crm/client/tags.rb, line 10
def tag(id)
  response = @connection.get("tags/#{id}")
  response['tag']
end
tag_body(fields) click to toggle source
# File lib/active_campaign_crm/client/tags.rb, line 61
def tag_body(fields)
  { 'tag': fields }.to_json
end
tags(params = {}) click to toggle source
# File lib/active_campaign_crm/client/tags.rb, line 5
def tags(params = {})
  response = @connection.get('tags', params)
  response['tags']
end
update_tag(id, fields) click to toggle source
# File lib/active_campaign_crm/client/tags.rb, line 43
def update_tag(id, fields)
  response = @connection.put("tags/#{id}", tag_body(fields))
  response['tag']
end