Skip to content

Commit 582029d

Browse files
authored
Add named parameter to list-transformations api.
1 parent 683252a commit 582029d

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
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
@@ -192,7 +192,7 @@ public ApiResponse tags(Map options) throws Exception {
192192

193193
public ApiResponse transformations(Map options) throws Exception {
194194
if (options == null) options = ObjectUtils.emptyMap();
195-
return callApi(HttpMethod.GET, Arrays.asList("transformations"), ObjectUtils.only(options, "next_cursor", "max_results"), options);
195+
return callApi(HttpMethod.GET, Arrays.asList("transformations"), ObjectUtils.only(options, "next_cursor", "max_results", "named"), options);
196196
}
197197

198198
public ApiResponse transformation(String transformation, Map options) throws Exception {

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public void testTransformationsWithCursor() throws Exception {
233233
Map result = api.transformations(ObjectUtils.asMap("max_results", 500, "next_cursor", next_cursor));
234234
transformations.addAll((List) result.get("transformations"));
235235
next_cursor = (String) result.get("next_cursor");
236-
} while (next_cursor != null );
236+
} while (next_cursor != null);
237237
assertThat(transformations, hasItem(allOf(hasEntry("name", "t_" + name))));
238238
}
239239

@@ -447,6 +447,45 @@ public void test17aTransformationDeleteImplicit() throws Exception {
447447
api.deleteTransformation(DELETE_TRANSFORMATION_NAME, ObjectUtils.emptyMap());
448448
}
449449

450+
@Test
451+
public void testListTransformationByNamed() throws Exception {
452+
String name = "a_test_named_transformation_param" + SUFFIX;
453+
try {
454+
api.createTransformation(name, "w_100", null);
455+
name = "t_" + name;
456+
List<Map> named = (List) api.transformations(ObjectUtils.asMap("max_results", 30, "named", true)).get("transformations");
457+
List<Map> unnamed = (List) api.transformations(ObjectUtils.asMap("max_results", 30, "named", false)).get("transformations");
458+
459+
// the named transformation should be present only in the named list:
460+
boolean unnamedFound = false;
461+
boolean namedFound = false;
462+
463+
for (Map t : unnamed) {
464+
if (t.get("name").equals(name)) {
465+
unnamedFound = true;
466+
break;
467+
}
468+
}
469+
470+
if (!unnamedFound) {
471+
for (Map t : named) {
472+
if (t.get("name").equals(name)) {
473+
namedFound = true;
474+
break;
475+
}
476+
}
477+
}
478+
479+
assertTrue("Named transformation wasn't returned with named=true param", namedFound);
480+
assertFalse("Named transformation returned with named=false param", unnamedFound);
481+
482+
} finally {
483+
try {
484+
api.deleteTransformation(name, null);
485+
} catch (Exception ignored){}
486+
}
487+
}
488+
450489
@Test
451490
public void test20ResourcesContext() throws Exception {
452491
Map result = api.resourcesByContext(TEST_KEY, ObjectUtils.emptyMap());

0 commit comments

Comments
 (0)