Skip to content

Commit 61ae183

Browse files
committed
resolved comments
1 parent e2477ed commit 61ae183

File tree

12 files changed

+511
-99
lines changed

12 files changed

+511
-99
lines changed

README.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ operations.
1111
ImageKit is a complete image optimization and transformation solution that comes with and
1212
[image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. It can be integrated with your
1313
existing infrastructure - storage like AWS s3, web servers, your CDN, and custom domain names, allowing you to deliver
14-
optimize images in minutes with minimal code changes.
14+
optimize images in minutes with minimal code changes
1515

1616
Table of contents -
1717
* [Installation](#installation)
@@ -500,10 +500,37 @@ It updates the file properties as per the [API documentation here](https://docs.
500500
The argument to the `updateDetail()` method is the object of `FileUpdateRequest` class, and the constructor will take the file ID and then set the parameters to be updated.
501501

502502
```java
503-
String fileId="your-file-id";
504-
FileUpdateRequest fileUpdateRequest =new FileUpdateRequest(fileId);
505-
fileUpdateRequest.setTags(List.of("Software","Developer","Engineer"));
503+
List<String> tags = new ArrayList<>();
504+
tags.add("Software");
505+
tags.add("Developer");
506+
tags.add("Engineer");
507+
508+
List<String> aiTags = new ArrayList<>();
509+
aiTags.add("Plant");
510+
FileUpdateRequest fileUpdateRequest = new FileUpdateRequest("fileId");
511+
fileUpdateRequest.setTags(tags);
512+
fileUpdateRequest.setRemoveAITags(aiTags);
513+
fileUpdateRequest.setWebhookUrl("https://webhook.site/c78d617f-33bc-40d9-9e61-608999721e2e");
514+
515+
JsonObject optionsInnerObject = new JsonObject();
516+
optionsInnerObject.addProperty("add_shadow", true);
517+
optionsInnerObject.addProperty("bg_color", "yellow");
518+
JsonObject innerObject1 = new JsonObject();
519+
innerObject1.addProperty("name", "remove-bg");
520+
innerObject1.add("options", optionsInnerObject);
521+
JsonObject innerObject2 = new JsonObject();
522+
innerObject2.addProperty("name", "google-auto-tagging");
523+
innerObject2.addProperty("minConfidence", 15);
524+
innerObject2.addProperty("maxTags", 20);
525+
JsonArray jsonArray = new JsonArray();
526+
jsonArray.add(innerObject1);
527+
jsonArray.add(innerObject2);
528+
529+
fileUpdateRequest.setExtensions(jsonArray);
506530
fileUpdateRequest.setCustomCoordinates("10,10,40,40");
531+
JsonObject jsonObjectCustomMetadata = new JsonObject();
532+
jsonObjectCustomMetadata.addProperty("test10", 11);
533+
fileUpdateRequest.setCustomMetadata(jsonObjectCustomMetadata);
507534
Result result=ImageKit.getInstance().updateFileDetail(fileUpdateRequest);
508535
System.out.println("======FINAL RESULT=======");
509536
System.out.println(result);
@@ -524,7 +551,7 @@ fileIds.add("FileId");
524551
List<String> tags = new ArrayList<>();
525552
tags.add("tag-to-add-1");
526553
tags.add("tag-to-add-2");
527-
ResultTags resultTags=ImageKit.getInstance().addTags(new TagsRequest(fileIds, tags), "addTags");
554+
ResultTags resultTags=ImageKit.getInstance().addTags(new TagsRequest(fileIds, tags));
528555
System.out.println("======FINAL RESULT=======");
529556
System.out.println(resultTags);
530557
System.out.println("Raw Response:");
@@ -544,7 +571,7 @@ fileIds.add("FileId");
544571
List<String> tags = new ArrayList<>();
545572
tags.add("tag-to-remove-1");
546573
tags.add("tag-to-remove-2");
547-
ResultTags resultTags=ImageKit.getInstance().removeTags(new TagsRequest(fileIds, tags), "removeTags");
574+
ResultTags resultTags=ImageKit.getInstance().removeTags(new TagsRequest(fileIds, tags));
548575
System.out.println("======FINAL RESULT=======");
549576
System.out.println(resultTags);
550577
System.out.println("Raw Response:");
@@ -861,6 +888,7 @@ The argument to the `createCustomMetaDataFields()` method is the object of `Cust
861888

862889
```java
863890
CustomMetaDataFieldSchemaObject schemaObject = new CustomMetaDataFieldSchemaObject();
891+
schemaObject.setType("Number");
864892
schemaObject.setMinValue(10);
865893
schemaObject.setMaxValue(200);
866894
CustomMetaDataFieldCreateRequest customMetaDataFieldCreateRequest = new CustomMetaDataFieldCreateRequest();

imagekit-sdk/src/main/java/io/imagekit/sdk/ImageKit.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.imagekit.sdk.tasks.Calculation;
1616
import io.imagekit.sdk.tasks.RestClient;
1717
import io.imagekit.sdk.tasks.UrlGen;
18+
import retrofit2.http.QueryMap;
1819

1920
import java.util.List;
2021
import java.util.Map;
@@ -105,13 +106,13 @@ public Result updateFileDetail(FileUpdateRequest fileUpdateRequest)
105106

106107
/**
107108
*
108-
* @param options is an map it may contain keys [ "path", "fileType", "tags",
109+
* @param getFileListRequest is an map it may contain keys [ "path", "fileType", "tags",
109110
* "includeFolder", "name", "limit", "skip"]
110111
* @return ResultList class that contains list of BaseFile
111112
*/
112-
public ResultList getFileList(Map<String, String> options) throws ForbiddenException, TooManyRequestsException,
113-
InternalServerException, UnauthorizedException, BadRequestException, UnknownException {
114-
return restClient.getFileList(options);
113+
public ResultList getFileList(@QueryMap GetFileListRequest getFileListRequest) throws ForbiddenException, TooManyRequestsException,
114+
InternalServerException, UnauthorizedException, BadRequestException, UnknownException, IllegalAccessException {
115+
return restClient.getFileList(getFileListRequest);
115116
}
116117

117118
/**

imagekit-sdk/src/main/java/io/imagekit/sdk/models/CustomMetaDataTypeEnum.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
package io.imagekit.sdk.models;
2-
3-
import com.google.gson.annotations.SerializedName;
4-
52
public enum CustomMetaDataTypeEnum {
63
Text, Textarea, Number, Date, Boolean, SingleSelect, MultiSelect;
74

imagekit-sdk/src/main/java/io/imagekit/sdk/models/FileUpdateRequest.java

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
package io.imagekit.sdk.models;
22

3-
import com.google.gson.Gson;
4-
import okhttp3.MediaType;
5-
import okhttp3.RequestBody;
3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonObject;
65

76
import java.util.List;
87

98
public class FileUpdateRequest {
109
private String fileId;
10+
public List<String> removeAITags;
11+
12+
public String webhookUrl;
13+
14+
public JsonArray extensions;
15+
1116
private List<String> tags;
1217
private String customCoordinates;
1318

19+
public JsonObject customMetadata;
20+
1421
public FileUpdateRequest(String fileId) {
1522
this.fileId = fileId;
1623
}
@@ -23,6 +30,30 @@ public void setFileId(String fileId) {
2330
this.fileId = fileId;
2431
}
2532

33+
public List<String> getRemoveAITags() {
34+
return removeAITags;
35+
}
36+
37+
public void setRemoveAITags(List<String> removeAITags) {
38+
this.removeAITags = removeAITags;
39+
}
40+
41+
public String getWebhookUrl() {
42+
return webhookUrl;
43+
}
44+
45+
public void setWebhookUrl(String webhookUrl) {
46+
this.webhookUrl = webhookUrl;
47+
}
48+
49+
public JsonArray getExtensions() {
50+
return extensions;
51+
}
52+
53+
public void setExtensions(JsonArray extensions) {
54+
this.extensions = extensions;
55+
}
56+
2657
public List<String> getTags() {
2758
return tags;
2859
}
@@ -39,12 +70,24 @@ public void setCustomCoordinates(String customCoordinates) {
3970
this.customCoordinates = customCoordinates;
4071
}
4172

73+
public JsonObject getCustomMetadata() {
74+
return customMetadata;
75+
}
76+
77+
public void setCustomMetadata(JsonObject customMetadata) {
78+
this.customMetadata = customMetadata;
79+
}
80+
4281
@Override
4382
public String toString() {
4483
return "FileUpdateRequest{" +
4584
"fileId='" + fileId + '\'' +
85+
", removeAITags=" + removeAITags +
86+
", webhookUrl='" + webhookUrl + '\'' +
87+
", extensions=" + extensions +
4688
", tags=" + tags +
4789
", customCoordinates='" + customCoordinates + '\'' +
90+
", customMetadata=" + customMetadata +
4891
'}';
4992
}
5093
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package io.imagekit.sdk.models;
2+
3+
import com.google.gson.JsonArray;
4+
5+
public class GetFileListRequest {
6+
public String type;
7+
public String sort;
8+
public String path;
9+
public String searchQuery;
10+
public String fileType;
11+
public String limit;
12+
public String skip;
13+
public String[] tags;
14+
15+
public String getType() {
16+
return type;
17+
}
18+
19+
public void setType(String type) {
20+
this.type = type;
21+
}
22+
23+
public String getSort() {
24+
return sort;
25+
}
26+
27+
public void setSort(String sort) {
28+
this.sort = sort;
29+
}
30+
31+
public String getPath() {
32+
return path;
33+
}
34+
35+
public void setPath(String path) {
36+
this.path = path;
37+
}
38+
39+
public String getSearchQuery() {
40+
return searchQuery;
41+
}
42+
43+
public void setSearchQuery(String searchQuery) {
44+
this.searchQuery = searchQuery;
45+
}
46+
47+
public String getFileType() {
48+
return fileType;
49+
}
50+
51+
public void setFileType(String fileType) {
52+
this.fileType = fileType;
53+
}
54+
55+
public String getLimit() {
56+
return limit;
57+
}
58+
59+
public void setLimit(String limit) {
60+
this.limit = limit;
61+
}
62+
63+
public String getSkip() {
64+
return skip;
65+
}
66+
67+
public void setSkip(String skip) {
68+
this.skip = skip;
69+
}
70+
71+
public String[] getTags() {
72+
return tags;
73+
}
74+
75+
public void setTags(String[] tags) {
76+
this.tags = tags;
77+
}
78+
79+
@Override
80+
public String toString() {
81+
return "GetFileListRequest{" +
82+
"type='" + type + '\'' +
83+
", sort='" + sort + '\'' +
84+
", path='" + path + '\'' +
85+
", searchQuery='" + searchQuery + '\'' +
86+
", fileType='" + fileType + '\'' +
87+
", limit='" + limit + '\'' +
88+
", skip='" + skip + '\'' +
89+
", tags=" + tags +
90+
'}';
91+
}
92+
}

imagekit-sdk/src/main/java/io/imagekit/sdk/tasks/MultipartBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ public MultipartBody build(FileCreateRequest fileCreateRequest) {
5454
if (null != fileCreateRequest.responseFields) {
5555
builder.addFormDataPart("responseFields", Utils.listToString(fileCreateRequest.responseFields));
5656
}
57-
if (fileCreateRequest.overwriteFile != null && !fileCreateRequest.overwriteFile) {
57+
if (fileCreateRequest.overwriteFile != null && fileCreateRequest.overwriteFile) {
5858
builder.addFormDataPart("overwriteFile", "true");
5959
}
60-
if (fileCreateRequest.overwriteAITags != null && !fileCreateRequest.overwriteAITags) {
60+
if (fileCreateRequest.overwriteAITags != null && fileCreateRequest.overwriteAITags) {
6161
builder.addFormDataPart("overwriteAITags", "true");
6262
}
63-
if (fileCreateRequest.overwriteTags != null && !fileCreateRequest.overwriteTags) {
63+
if (fileCreateRequest.overwriteTags != null && fileCreateRequest.overwriteTags) {
6464
builder.addFormDataPart("overwriteTags", "true");
6565
}
66-
if (fileCreateRequest.overwriteCustomMetadata != null && !fileCreateRequest.overwriteCustomMetadata) {
66+
if (fileCreateRequest.overwriteCustomMetadata != null && fileCreateRequest.overwriteCustomMetadata) {
6767
builder.addFormDataPart("overwriteCustomMetadata", "true");
6868
}
6969
if (null != fileCreateRequest.extensions) {

imagekit-sdk/src/main/java/io/imagekit/sdk/tasks/RestClient.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.imagekit.sdk.models.DeleteFileVersionRequest;
2626
import io.imagekit.sdk.models.DeleteFolderRequest;
2727
import io.imagekit.sdk.models.FileCreateRequest;
28+
import io.imagekit.sdk.models.GetFileListRequest;
2829
import io.imagekit.sdk.models.MoveFileRequest;
2930
import io.imagekit.sdk.models.MoveFolderRequest;
3031
import io.imagekit.sdk.models.MetaData;
@@ -66,6 +67,7 @@ public Result upload(FileCreateRequest fileCreateRequest) throws InternalServerE
6667
request = new Request.Builder().url(UPLOAD_BASE_URL.concat("api/v1/files/upload")).post(body)
6768
.headers(Headers.of(headers)).build();
6869

70+
6971
try {
7072
Response response = client.newCall(request).execute();
7173
String respBody = "";
@@ -112,16 +114,17 @@ public Result updateFileDetail(FileUpdateRequest fileUpdateRequest)
112114
return result;
113115
}
114116

115-
public ResultList getFileList(Map<String, String> options) throws ForbiddenException, TooManyRequestsException,
117+
public ResultList getFileList(GetFileListRequest getFileListRequest) throws ForbiddenException, TooManyRequestsException,
116118
InternalServerException, UnauthorizedException, BadRequestException, UnknownException {
117119
ResultList resultList = new ResultList();
118120
Map<String, String> headers = Utils.getHeaders(imageKit);
119121

122+
// ObjectMap objectMapper = new ObjectMapper();
123+
// ModelMapp
120124
QueryMaker queryMaker = new QueryMaker();
121-
122-
for (Map.Entry<String, String> entry : options.entrySet()) {
123-
queryMaker.put(String.format("%s=%s", entry.getKey(), entry.getValue()));
124-
}
125+
// for (Map.Entry<String, String> entry : ) {
126+
// queryMaker.put(String.format("%s=%s", entry.getKey(), entry.getValue()));
127+
// }
125128

126129
String url = String.format(Locale.US, API_BASE_URL.concat("v1/files?%s"), queryMaker.get());
127130

@@ -300,7 +303,6 @@ public ResultCache purgeCache(String url) throws ForbiddenException, TooManyRequ
300303

301304
try {
302305
Response response = client.newCall(request).execute();
303-
System.out.println("res:==> " + response.request().body());
304306
String respBody = "";
305307
if (response.code() == 200 || response.code() == 201) {
306308
respBody = response.body().string();
@@ -344,7 +346,7 @@ public ResultCacheStatus getPurgeCacheStatus(String requestId) throws ForbiddenE
344346
return result;
345347
}
346348

347-
private ResultTags manageTags(TagsRequest tagsRequest, String action)
349+
public ResultTags manageTags(TagsRequest tagsRequest, String action)
348350
throws NotFoundException, PartialSuccessException, BadRequestException, InternalServerException,
349351
UnknownException, ForbiddenException, TooManyRequestsException, UnauthorizedException {
350352
ResultTags resultTags = new ResultTags();

imagekit-sdk/src/main/java/io/imagekit/sdk/utils/Utils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ public static void throwOtherException(Response response)
177177

178178
public static ResultException populateResult(Response response) throws IOException {
179179
String resp = response.body().string();
180-
System.out.println("resp:==> " + resp);
181180
ResultException result = new Gson().fromJson(resp, ResultException.class);
182181
populateResponseMetadata(resp, result.getResponseMetaData(), response.code(), response.headers().toMultimap());
183182
return result;

imagekit-sdk/src/test/java/io/imagekit/sdk/ImageKitTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import static org.junit.Assert.assertNotNull;
1010

1111
public class ImageKitTest {
12+
private ImageKit SUT;
1213

1314
@Test
1415
public void imageKit_configurationTest() {

0 commit comments

Comments
 (0)