Skip to content

Commit

Permalink
Merge pull request maximadeka#17 from memberful/create-tags
Browse files Browse the repository at this point in the history
Add possibility to create tags
  • Loading branch information
Raymond Cudjoe authored Feb 6, 2018
2 parents 279c629 + bbe9236 commit 7100edb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ API actions are available as methods on the client object. Currently, the Conver
| Add subscriber to sequence | `#add_subscriber_to_sequence(sequence_id, email, options = {})`|
| List tags | `#tags` |
| Add subscriber to tag | `#add_subscriber_to_tag(tag_id, email, options = {})`|
| Create a tag | `#create_tag(tag_name)` |
| Create multiple tags | `#create_tags(tag_names)`|
| List forms | `#forms` |
| Add subscriber to form | `#add_subscriber_to_form(form_id, email, options = {})`|
| Unsubscribe | `#unsubscribe(email)` |
Expand Down
14 changes: 14 additions & 0 deletions lib/convertkit/client/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ def add_subscriber_to_tag(tag_id, email, options = {})
f.params['tags'] = options[:tags]
end
end

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

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
end
end
end
23 changes: 23 additions & 0 deletions spec/convertkit/client/tags_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "spec_helper"
require "securerandom"

module Convertkit
class Client
Expand Down Expand Up @@ -30,6 +31,28 @@ class Client
expect(r.body).to_not eql({"error"=>"Missing parameter","message"=>"Subscriber email is required"})
end
end

describe "#create_tag" do
it "creates a tag" do
tag_name = "tag-#{SecureRandom.hex}"

tag = @client.create_tag(tag_name)

expect(tag["name"]).to eq(tag_name)
end
end

describe "#create_tags" do
it "creates multiple tags" do
tag_name1 = "tag-#{SecureRandom.hex}"
tag_name2 = "tag-#{SecureRandom.hex}"

tags = @client.create_tags([tag_name1, tag_name2])

expect(tags[0]["name"]).to eq(tag_name1)
expect(tags[1]["name"]).to eq(tag_name2)
end
end
end
end
end

0 comments on commit 7100edb

Please sign in to comment.