Module: Convertkit::Client::Tags

Included in:
Convertkit::Client
Defined in:
lib/convertkit/client/tags.rb

Instance Method Summary collapse

Instance Method Details

#add_subscriber_to_tag(tag_id, email, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/convertkit/client/tags.rb', line 8

def add_subscriber_to_tag(tag_id, email, options = {})
  connection.post("tags/#{tag_id}/subscribe") do |f|
    f.params['email'] = email
    f.params['first_name'] = options[:first_name]
    f.params['fields'] = options[:fields]
    f.params['tags'] = options[:tags]
  end
end

#create_tag(tag_name) ⇒ Object



27
28
29
30
31
32
# File 'lib/convertkit/client/tags.rb', line 27

def create_tag(tag_name)
  response = connection.post("tags") do |request|
    request.params["tag"] = { name: tag_name }
  end
  response.body
end

#create_tags(tag_names) ⇒ Object



34
35
36
37
38
39
# File 'lib/convertkit/client/tags.rb', line 34

def create_tags(tag_names)
  response = connection.post("tags") do |request|
    request.params["tag"] = tag_names.map { |tag_name| { name: tag_name } }
  end
  response.body
end

#remove_tag_from_subscriber(tag_id, subscriber_id) ⇒ Object



17
18
19
# File 'lib/convertkit/client/tags.rb', line 17

def remove_tag_from_subscriber(tag_id, subscriber_id)
  connection.delete("subscribers/#{subscriber_id}/tags/#{tag_id}")
end

#remove_tag_from_subscriber_by_email(tag_id, email) ⇒ Object



21
22
23
24
25
# File 'lib/convertkit/client/tags.rb', line 21

def remove_tag_from_subscriber_by_email(tag_id, email)
  connection.post("tags/#{tag_id}/unsubscribe") do |f|
    f.params['email'] = email
  end
end

#subscriptions_to_tag(tag_id, options = {}) ⇒ Object



41
42
43
44
45
46
# File 'lib/convertkit/client/tags.rb', line 41

def subscriptions_to_tag(tag_id, options = {})
  connection.get("tags/#{tag_id}/subscriptions", options) do |f|
    f.params["sort_order"] = options[:sort_order] if options[:sort_order]
    f.params["subscriber_state"] = options[:subscriber_state] if options[:subscriber_state]
  end
end

#tagsObject



4
5
6
# File 'lib/convertkit/client/tags.rb', line 4

def tags
  connection.get("tags")
end