Skip to content

Commit 24f32f6

Browse files
authored
Merge pull request #278 from crowdin/screenshots-api-updates
feat: screenshots api updates
2 parents 2101227 + 7dd727a commit 24f32f6

File tree

5 files changed

+55
-24
lines changed

5 files changed

+55
-24
lines changed

src/main/java/com/crowdin/client/core/model/Pagination.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
@Data
66
public class Pagination {
7-
private int offset;
8-
private int limit;
7+
private Integer offset;
8+
private Integer limit;
99
}

src/main/java/com/crowdin/client/screenshots/ScreenshotsApi.java

+33-22
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,7 @@
99
import com.crowdin.client.core.model.PatchRequest;
1010
import com.crowdin.client.core.model.ResponseList;
1111
import com.crowdin.client.core.model.ResponseObject;
12-
import com.crowdin.client.screenshots.model.AddScreenshotRequest;
13-
import com.crowdin.client.screenshots.model.AddTagRequest;
14-
import com.crowdin.client.screenshots.model.ReplaceTagsRequest;
15-
import com.crowdin.client.screenshots.model.Screenshot;
16-
import com.crowdin.client.screenshots.model.ScreenshotResponseList;
17-
import com.crowdin.client.screenshots.model.ScreenshotResponseObject;
18-
import com.crowdin.client.screenshots.model.Tag;
19-
import com.crowdin.client.screenshots.model.TagResponseList;
20-
import com.crowdin.client.screenshots.model.TagResponseObject;
21-
import com.crowdin.client.screenshots.model.UpdateScreenshotRequest;
12+
import com.crowdin.client.screenshots.model.*;
2213

2314
import java.util.List;
2415
import java.util.Map;
@@ -46,13 +37,11 @@ public ScreenshotsApi(Credentials credentials, ClientConfig clientConfig) {
4637
*/
4738
@Deprecated
4839
public ResponseList<Screenshot> listScreenshots(Long projectId, Long stringId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
49-
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
50-
"stringId", Optional.ofNullable(stringId),
51-
"limit", Optional.ofNullable(limit),
52-
"offset", Optional.ofNullable(offset)
53-
);
54-
ScreenshotResponseList screenshotResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/screenshots", new HttpRequestConfig(queryParams), ScreenshotResponseList.class);
55-
return ScreenshotResponseList.to(screenshotResponseList);
40+
ListScreenshotsParams screenshotsParams = new ListScreenshotsParams();
41+
screenshotsParams.setStringIds(Optional.ofNullable(stringId).map(Object::toString).orElse(null));
42+
screenshotsParams.setLimit(limit);
43+
screenshotsParams.setOffset(offset);
44+
return this.listScreenshots(projectId, screenshotsParams);
5645
}
5746

5847
/**
@@ -69,12 +58,34 @@ public ResponseList<Screenshot> listScreenshots(Long projectId, Long stringId, I
6958
* </ul>
7059
*/
7160
public ResponseList<Screenshot> listScreenshots(Long projectId, List<String> stringIds, List<String> labelIds, List<String> excludeLabelIds, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
61+
ListScreenshotsParams screenshotsParams = new ListScreenshotsParams();
62+
screenshotsParams.setStringIds(Optional.ofNullable(stringIds).map(l -> String.join(",", l)).orElse(null));
63+
screenshotsParams.setLabelIds(Optional.ofNullable(labelIds).map(l -> String.join(",", l)).orElse(null));
64+
screenshotsParams.setExcludeLabelIds(Optional.ofNullable(excludeLabelIds).map(l -> String.join(",", l)).orElse(null));
65+
screenshotsParams.setLimit(limit);
66+
screenshotsParams.setOffset(offset);
67+
return this.listScreenshots(projectId, screenshotsParams);
68+
}
69+
70+
/**
71+
* @param projectId project identifier
72+
* @param params query params
73+
* @return list of screenshots
74+
* @see <ul>
75+
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.screenshots.getMany" target="_blank"><b>API Documentation</b></a></li>
76+
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.screenshots.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
77+
* </ul>
78+
*/
79+
public ResponseList<Screenshot> listScreenshots(Long projectId, ListScreenshotsParams params) throws HttpException, HttpBadRequestException {
80+
ListScreenshotsParams query = Optional.ofNullable(params).orElse(new ListScreenshotsParams());
7281
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
73-
"stringIds", Optional.ofNullable(stringIds),
74-
"labelIds", Optional.ofNullable(labelIds),
75-
"excludeLabelIds", Optional.ofNullable(excludeLabelIds),
76-
"limit", Optional.ofNullable(limit),
77-
"offset", Optional.ofNullable(offset)
82+
"search", Optional.ofNullable(query.getSearch()),
83+
"orderBy", Optional.ofNullable(query.getOrderBy()),
84+
"stringIds", Optional.ofNullable(query.getStringIds()),
85+
"labelIds", Optional.ofNullable(query.getLabelIds()),
86+
"excludeLabelIds", Optional.ofNullable(query.getExcludeLabelIds()),
87+
"limit", Optional.ofNullable(query.getLimit()),
88+
"offset", Optional.ofNullable(query.getOffset())
7889
);
7990
ScreenshotResponseList screenshotResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/screenshots", new HttpRequestConfig(queryParams), ScreenshotResponseList.class);
8091
return ScreenshotResponseList.to(screenshotResponseList);

src/main/java/com/crowdin/client/screenshots/model/AutoTagReplaceTagsRequest.java

+3
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
public class AutoTagReplaceTagsRequest extends ReplaceTagsRequest {
99

1010
private Boolean autoTag;
11+
private Long fileId;
12+
private Long branchId;
13+
private Long directoryId;
1114
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.crowdin.client.screenshots.model;
2+
3+
import com.crowdin.client.core.model.Pagination;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
7+
@EqualsAndHashCode(callSuper = true)
8+
@Data
9+
public class ListScreenshotsParams extends Pagination {
10+
11+
private String search;
12+
private String orderBy;
13+
private String stringIds;
14+
private String labelIds;
15+
private String excludeLabelIds;
16+
}

src/main/java/com/crowdin/client/screenshots/model/UpdateScreenshotRequest.java

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ public class UpdateScreenshotRequest {
77

88
private Long storageId;
99
private String name;
10+
private Boolean usePreviousTags;
1011
}

0 commit comments

Comments
 (0)