Skip to content

Commit 04914ae

Browse files
nitzanjtocker
authored andcommitted
Add type parameter to Api.publishResource() (#73)
1 parent 5c64a5d commit 04914ae

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ private ApiResponse publishResource(String byKey, Object value, Map options) thr
330330
uri.add("publish_resources");
331331
Map params = new HashMap<String, Object>();
332332
params.put(byKey, value);
333-
params.putAll(ObjectUtils.only(options, "invalidate", "overwrite"));
333+
params.putAll(ObjectUtils.only(options, "invalidate", "overwrite", "type"));
334334
return callApi(HttpMethod.POST, uri, params, options);
335335
}
336336

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,35 @@ public void testPublishByIds() throws Exception {
762762
cloudinary.uploader().destroy(publicId, null);
763763
}
764764

765+
@Test
766+
public void testPublishWithType() throws Exception {
767+
Map response = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("tags", uniqueTag, "type", "authenticated"));
768+
String publicId = (String) response.get("public_id");
769+
770+
// publish with wrong type - verify publish fails
771+
response = cloudinary.api().publishByIds(Arrays.asList(publicId), ObjectUtils.asMap("type", "private"));
772+
List published = (List) response.get("published");
773+
List failed = (List) response.get("failed");
774+
assertNotNull(published);
775+
assertNotNull(failed);
776+
assertEquals(published.size(), 0);
777+
assertEquals(failed.size(), 1);
778+
779+
// publish with correct type - verify publish succeeds
780+
response = cloudinary.api().publishByIds(Arrays.asList(publicId), ObjectUtils.asMap("type", "authenticated"));
781+
published = (List) response.get("published");
782+
failed = (List) response.get("failed");
783+
assertNotNull(published);
784+
assertNotNull(failed);
785+
assertEquals(published.size(), 1);
786+
assertEquals(failed.size(), 0);
787+
788+
Map resource = (Map) published.get(0);
789+
assertEquals(resource.get("public_id"), publicId);
790+
assertNotNull(resource.get("url"));
791+
cloudinary.uploader().destroy(publicId, null);
792+
}
793+
765794
@Test
766795
public void testPublishByPrefix() throws Exception {
767796
Map response = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("tags", uniqueTag, "type", "authenticated"));

0 commit comments

Comments
 (0)