Skip to content

Commit fd41e66

Browse files
authored
Fix transformations API call
1 parent cfa2d10 commit fd41e66

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,24 +235,30 @@ public ApiResponse transformations(Map options) throws Exception {
235235

236236
public ApiResponse transformation(String transformation, Map options) throws Exception {
237237
if (options == null) options = ObjectUtils.emptyMap();
238-
return callApi(HttpMethod.GET, Arrays.asList("transformations", transformation), ObjectUtils.only(options, "next_cursor", "max_results"), options);
238+
Map map = ObjectUtils.only(options, "next_cursor", "max_results");
239+
map.put("transformation", transformation);
240+
return callApi(HttpMethod.GET, Arrays.asList("transformations"), map, options);
239241
}
240242

241243
public ApiResponse deleteTransformation(String transformation, Map options) throws Exception {
242244
if (options == null) options = ObjectUtils.emptyMap();
243-
return callApi(HttpMethod.DELETE, Arrays.asList("transformations", transformation), ObjectUtils.emptyMap(), options);
245+
Map updates = ObjectUtils.asMap("transformation", transformation);
246+
return callApi(HttpMethod.DELETE, Arrays.asList("transformations"), updates, options);
244247
}
245248

246249
// updates - currently only supported update are:
247250
// "allowed_for_strict": boolean flag
248251
// "unsafe_update": transformation string
249252
public ApiResponse updateTransformation(String transformation, Map updates, Map options) throws Exception {
250253
if (options == null) options = ObjectUtils.emptyMap();
251-
return callApi(HttpMethod.PUT, Arrays.asList("transformations", transformation), updates, options);
254+
updates.put("transformation", transformation);
255+
return callApi(HttpMethod.PUT, Arrays.asList("transformations"), updates, options);
252256
}
253257

254258
public ApiResponse createTransformation(String name, String definition, Map options) throws Exception {
255-
return callApi(HttpMethod.POST, Arrays.asList("transformations", name), ObjectUtils.asMap("transformation", definition), options);
259+
return callApi(HttpMethod.POST,
260+
Arrays.asList("transformations"),
261+
ObjectUtils.asMap("transformation", definition, "name", name), options);
256262
}
257263

258264
public ApiResponse uploadPresets(Map options) throws Exception {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public String generate(Iterable<Map> optionsList) {
3636
}
3737
}
3838

39-
if (StringUtils.isNotBlank(format)){
39+
if (format != null){
4040
components.add(format);
4141
}
4242

@@ -48,7 +48,7 @@ public String generate(Map options) {
4848
List<String> eager = new ArrayList<String>();
4949
eager.add(super.generate(options));
5050

51-
if (StringUtils.isNotBlank(format)){
51+
if (format != null){
5252
eager.add(format);
5353
}
5454

cloudinary-core/src/test/java/com/cloudinary/TransformationTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ public void testContextMetadataToUserVariables() {
307307
assertEquals("$xpos_ctx:!x_pos!_to_f,$ypos_ctx:!y_pos!_to_f,c_crop,x_$xpos_mul_w,y_$ypos_mul_h", t.generate());
308308
}
309309

310+
@Test
311+
public void testFormatInTransformation() {
312+
String t = new EagerTransformation().width(100).format("jpeg").generate();
313+
assertEquals("w_100/jpeg", t);
314+
315+
t = new EagerTransformation().width(100).format("").generate();
316+
assertEquals("w_100/", t);
317+
}
318+
310319
@Parameters({ "angle",
311320
"aspect_ratio",
312321
"dpr",

0 commit comments

Comments
 (0)