Skip to content

Commit 5d2c01b

Browse files
author
Amir Tocker
committed
Add removeAllTags API
1 parent 247b5fd commit 5d2c01b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

cloudinary-core/src/main/java/com/cloudinary/Uploader.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ public Map removeTag(String tag, String[] publicIds, Map options) throws IOExcep
277277
return callTagsApi(tag, "remove", publicIds, options);
278278
}
279279

280+
public Map removeAllTags(String[] publicIds, Map options) throws IOException {
281+
if (options == null)
282+
options = ObjectUtils.emptyMap();
283+
return callTagsApi(null, "remove_all", publicIds, options);
284+
}
285+
280286
public Map replaceTag(String tag, String[] publicIds, Map options) throws IOException {
281287
if (options == null)
282288
options = ObjectUtils.emptyMap();
@@ -287,7 +293,9 @@ public Map callTagsApi(String tag, String command, String[] publicIds, Map optio
287293
if (options == null)
288294
options = ObjectUtils.emptyMap();
289295
Map<String, Object> params = new HashMap<String, Object>();
290-
params.put("tag", tag);
296+
if (tag != null) {
297+
params.put("tag", tag);
298+
}
291299
params.put("command", command);
292300
params.put("type", (String) options.get("type"));
293301
params.put("public_ids", Arrays.asList(publicIds));

cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractUploaderTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.cloudinary.utils.ObjectUtils;
55
import com.cloudinary.utils.Rectangle;
66
import org.cloudinary.json.JSONArray;
7+
import org.hamcrest.Matcher;
8+
import org.hamcrest.Matchers;
79
import org.junit.*;
810
import org.junit.rules.TestName;
911

@@ -13,6 +15,7 @@
1315
import java.util.*;
1416
import java.util.zip.ZipInputStream;
1517

18+
import static org.hamcrest.Matchers.*;
1619
import static org.junit.Assert.*;
1720
import static org.junit.Assume.assumeNotNull;
1821

@@ -226,6 +229,12 @@ public void testTags() throws Exception {
226229
cloudinary.uploader().replaceTag("tag3", new String[]{public_id}, ObjectUtils.emptyMap());
227230
tags = (List<String>) cloudinary.api().resource(public_id, ObjectUtils.emptyMap()).get("tags");
228231
assertEquals(tags, ObjectUtils.asArray(new String[]{"tag3"}));
232+
result = cloudinary.uploader().removeAllTags(new String[]{public_id, public_id2, "noSuchId"}, ObjectUtils.emptyMap());
233+
List<String> publicIds = (List<String>) result.get("public_ids");
234+
assertThat(publicIds, containsInAnyOrder(public_id, public_id2)); // = and not containing "noSuchId"
235+
result = cloudinary.api().resource(public_id, ObjectUtils.emptyMap());
236+
assertThat((Map<? extends String, ?>) result, not(hasKey("tags")));
237+
229238
}
230239

231240
@Test

0 commit comments

Comments
 (0)