Skip to content

Commit 926544e

Browse files
author
Amir Tocker
committed
Merge branch 'feature/publish-api'
# Conflicts: # cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractApiTest.java
2 parents 8c482a9 + eddbf8c commit 926544e

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,39 @@ public ApiResponse createUploadMapping(String name, Map options) throws Exceptio
275275
return callApi(HttpMethod.POST, Arrays.asList("upload_mappings"), params, options);
276276
}
277277

278+
public ApiResponse publishByPrefix(String prefix, Map options) throws Exception {
279+
if (options == null) options = ObjectUtils.emptyMap();
280+
String resourceType = ObjectUtils.asString(options.get("resource_type"), "image");
281+
List<String> uri = new ArrayList<String>();
282+
uri.add("publish_resources");
283+
uri.add(resourceType);
284+
Map params = new HashMap<String, Object>();
285+
params.put("prefix", prefix);
286+
params.putAll(ObjectUtils.only(options, "invalidate", "overwrite"));
287+
return callApi(HttpMethod.POST, uri, params, options);
288+
}
289+
290+
public ApiResponse publishByTag(String tag, Map options) throws Exception {
291+
if (options == null) options = ObjectUtils.emptyMap();
292+
String resourceType = ObjectUtils.asString(options.get("resource_type"), "image");
293+
List<String> uri = new ArrayList<String>();
294+
uri.add("publish_resources");
295+
uri.add(resourceType);
296+
Map params = new HashMap<String, Object>();
297+
params.put("tag", tag);
298+
params.putAll(ObjectUtils.only(options, "invalidate", "overwrite"));
299+
return callApi(HttpMethod.POST, uri, params, options);
300+
}
301+
302+
public ApiResponse publishByIds(Iterable<String> publicIds, Map options) throws Exception {
303+
if (options == null) options = ObjectUtils.emptyMap();
304+
String resourceType = ObjectUtils.asString(options.get("resource_type"), "image");
305+
List<String> uri = new ArrayList<String>();
306+
uri.add("publish_resources");
307+
uri.add(resourceType);
308+
Map params = new HashMap<String, Object>();
309+
params.put("public_ids", publicIds);
310+
params.putAll(ObjectUtils.only(options, "invalidate", "overwrite"));
311+
return callApi(HttpMethod.POST, uri, params, options);
312+
}
278313
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public Map rename(String fromPublicId, String toPublicId, Map options) throws IO
165165
params.put("from_public_id", fromPublicId);
166166
params.put("to_public_id", toPublicId);
167167
params.put("invalidate", ObjectUtils.asBoolean(options.get("invalidate"), false).toString());
168+
params.put("to_type", options.get("to_type"));
168169
return callApi("rename", params, options, null);
169170
}
170171

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,4 +697,46 @@ public void testUploadMapping() throws Exception {
697697
}
698698
assertTrue(!found);
699699
}
700+
701+
@Test
702+
public void testPublishByIds() throws Exception {
703+
Map response = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("tags", SDK_TEST_TAG, "type", "authenticated"));
704+
String publicId = (String) response.get("public_id");
705+
response = cloudinary.api().publishByIds(Arrays.asList(publicId), null);
706+
List published = (List) response.get("published");
707+
assertNotNull(published);
708+
assertEquals(published.size(), 1);
709+
Map resource = (Map) published.get(0);
710+
assertEquals(resource.get("public_id"), publicId);
711+
assertNotNull(resource.get("url"));
712+
cloudinary.uploader().destroy(publicId, null);
713+
}
714+
715+
@Test
716+
public void testPublishByPrefix() throws Exception {
717+
Map response = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("tags", SDK_TEST_TAG, "type", "authenticated"));
718+
String publicId = (String) response.get("public_id");
719+
response = cloudinary.api().publishByPrefix(publicId.substring(0, publicId.length() - 2), null);
720+
List published = (List) response.get("published");
721+
assertNotNull(published);
722+
assertEquals(published.size(), 1);
723+
Map resource = (Map) published.get(0);
724+
assertEquals(resource.get("public_id"), publicId);
725+
assertNotNull(resource.get("url"));
726+
cloudinary.uploader().destroy(publicId, null);
727+
}
728+
729+
@Test
730+
public void testPublishByTag() throws Exception {
731+
Map response = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("tags", Arrays.asList(SDK_TEST_TAG, SDK_TEST_TAG + "1"), "type", "authenticated"));
732+
String publicId = (String) response.get("public_id");
733+
response = cloudinary.api().publishByTag(SDK_TEST_TAG + "1", null);
734+
List published = (List) response.get("published");
735+
assertNotNull(published);
736+
assertEquals(published.size(), 1);
737+
Map resource = (Map) published.get(0);
738+
assertEquals(resource.get("public_id"), publicId);
739+
assertNotNull(resource.get("url"));
740+
cloudinary.uploader().destroy(publicId, null);
741+
}
700742
}

0 commit comments

Comments
 (0)