Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit a4f872a

Browse files
author
Marcin Chochowski
committed
allow adding and removing tags
1 parent baa8492 commit a4f872a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/creatubbles/creation.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ def update_tags(tags)
3333
@connection.put("creations/#{id}", :body => { 'data' => { 'type' => 'creations', 'attributes': {'tags' => tags }}})
3434
end
3535

36+
def add_tags(tags)
37+
tags_data = tags.map { |tag| {type: 'tags', id: tag} }
38+
@connection.post("creations/#{id}/tags", body: { data: tags_data })
39+
end
40+
41+
def remove_tags(tags)
42+
tags_data = tags.map { |tag| {type: 'tags', id: tag} }
43+
@connection.delete("creations/#{id}/tags", body: { data: tags_data })
44+
end
45+
3646
def upload(file)
3747
extension = File.extname(file)[1..-1]
3848
res = @connection.post("creations/#{id}/uploads", :params => { 'extension' => extension })

spec/creatubbles/creation_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,30 @@
3838
expect(subject.creators).to eq ['xUt6Feou']
3939
end
4040
end
41+
42+
describe 'add_tags' do
43+
it "should trigger post on connection with correct params" do
44+
expect(connection).to receive(:post).with(
45+
"creations/#{subject.id}/tags", {
46+
body: {
47+
data: [
48+
{ type: "tags", id: "a" },
49+
{ type: "tags", id: "b" }
50+
]}})
51+
subject.add_tags(['a', 'b'])
52+
end
53+
end
54+
55+
describe 'remove_tags' do
56+
it "should trigger post on connection with correct params" do
57+
expect(connection).to receive(:delete).with(
58+
"creations/#{subject.id}/tags", {
59+
body: {
60+
data: [
61+
{ type: "tags", id: "a" },
62+
{ type: "tags", id: "b" }
63+
]}})
64+
subject.remove_tags(['a', 'b'])
65+
end
66+
end
4167
end

0 commit comments

Comments
 (0)