forked from crowdin/crowdin-api-client-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabelsApi.java
More file actions
203 lines (188 loc) · 11.7 KB
/
LabelsApi.java
File metadata and controls
203 lines (188 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package com.crowdin.client.labels;
import com.crowdin.client.core.CrowdinApi;
import com.crowdin.client.core.http.HttpRequestConfig;
import com.crowdin.client.core.http.exceptions.HttpBadRequestException;
import com.crowdin.client.core.http.exceptions.HttpException;
import com.crowdin.client.core.model.*;
import com.crowdin.client.labels.model.AddLabelRequest;
import com.crowdin.client.labels.model.Label;
import com.crowdin.client.labels.model.LabelResponseList;
import com.crowdin.client.labels.model.LabelResponseObject;
import com.crowdin.client.labels.model.LabelToScreenshotsRequest;
import com.crowdin.client.labels.model.LabelToStringsRequest;
import com.crowdin.client.screenshots.model.Screenshot;
import com.crowdin.client.screenshots.model.ScreenshotResponseList;
import com.crowdin.client.sourcestrings.model.SourceString;
import com.crowdin.client.sourcestrings.model.SourceStringResponseList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
public class LabelsApi extends CrowdinApi {
public LabelsApi(Credentials credentials) {
super(credentials);
}
public LabelsApi(Credentials credentials, ClientConfig clientConfig) {
super(credentials, clientConfig);
}
/**
* @param projectId Project Identifier
* @param limit A maximum number of items to retrieve. Default: 25
* @param offset A starting offset in the collection. Default: 0
* @param isSystem Filter collection by isSystem value
* @return list of labels
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.labels.getMany" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.labels.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<Label> listLabels(Long projectId, Integer limit, Integer offset, BooleanInt isSystem) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/labels", this.url, projectId);
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset),
"isSystem", Optional.ofNullable(isSystem)
);
LabelResponseList labelResponseList = this.httpClient.get(builtUrl, new HttpRequestConfig(queryParams), LabelResponseList.class);
return LabelResponseList.to(labelResponseList);
}
/**
* @param projectId Project Identifier
* @param limit A maximum number of items to retrieve. Default: 25
* @param offset A starting offset in the collection. Default: 0
* @param isSystem Filter collection by isSystem value
* @param orderBy list of OrderByField
* @return list of labels
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.labels.getMany" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.labels.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<Label> listLabels(Long projectId, Integer limit, Integer offset, BooleanInt isSystem, List<OrderByField> orderBy) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/labels", this.url, projectId);
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset),
"isSystem", Optional.ofNullable(isSystem),
"orderBy", Optional.ofNullable(OrderByField.generateSortParam(orderBy))
);
LabelResponseList labelResponseList = this.httpClient.get(builtUrl, new HttpRequestConfig(queryParams), LabelResponseList.class);
return LabelResponseList.to(labelResponseList);
}
/**
* @param projectId Project Identifier
* @param request Request object
* @return created label
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.labels.post" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.labels.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<Label> addLabel(Long projectId, AddLabelRequest request) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/labels", this.url, projectId);
LabelResponseObject response = this.httpClient.post(builtUrl, request, new HttpRequestConfig(), LabelResponseObject.class);
return ResponseObject.of(response.getData());
}
/**
* @param projectId Project Identifier
* @param labelId Label Identifier
* @return label
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.labels.get" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.labels.get" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<Label> getLabel(Long projectId, Long labelId) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId);
LabelResponseObject response = this.httpClient.get(builtUrl, new HttpRequestConfig(), LabelResponseObject.class);
return ResponseObject.of(response.getData());
}
/**
* @param projectId Project Identifier
* @param labelId Label Identifier
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.labels.delete" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.labels.delete" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public void deleteLabel(Long projectId, Long labelId) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId);
this.httpClient.delete(builtUrl, new HttpRequestConfig(), Void.class);
}
/**
* @param projectId Project Identifier
* @param labelId Label Identifier
* @param request Request object
* @return edited label
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.labels.patch" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.labels.patch" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<Label> editLabel(Long projectId, Long labelId, List<PatchRequest> request) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId);
LabelResponseObject response = this.httpClient.patch(builtUrl, request, new HttpRequestConfig(), LabelResponseObject.class);
return ResponseObject.of(response.getData());
}
/**
* @param projectId Project Identifier
* @param labelId Label Identifier
* @param request Request object
* @return Source string
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.labels.strings.post" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.labels.strings.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<SourceString> assignLabelToStrings(Long projectId, Long labelId, LabelToStringsRequest request) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/labels/%d/strings", this.url, projectId, labelId);
SourceStringResponseList response = this.httpClient.post(builtUrl, request, new HttpRequestConfig(), SourceStringResponseList.class);
return SourceStringResponseList.to(response);
}
/**
* @param projectId Project Identifier
* @param labelId Label Identifier
* @param stringIds List of string IDs
* @return Source string
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.labels.strings.deleteMany" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.labels.strings.deleteMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<SourceString> unassignLabelFromStrings(Long projectId, Long labelId, List<Long> stringIds) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/labels/%d/strings", this.url, projectId, labelId);
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams("stringIds", Optional.ofNullable(stringIds == null ? null : stringIds.stream().map(String::valueOf).collect(Collectors.joining(","))));
SourceStringResponseList response = this.httpClient.delete(builtUrl, new HttpRequestConfig(queryParams), SourceStringResponseList.class);
return SourceStringResponseList.to(response);
}
/**
* @param projectId Project Identifier
* @param labelId Label Identifier
* @param request Request Object
* @return Screenshots
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.labels.screenshots.post" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.labels.screenshots.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<Screenshot> assignLabelToScreenshots(Long projectId, Long labelId, LabelToScreenshotsRequest request) throws HttpException, HttpBadRequestException{
String builtUrl = String.format("%s/projects/%d/labels/%d/screenshots", this.url, projectId, labelId);
ScreenshotResponseList response = this.httpClient.post(builtUrl, request, new HttpRequestConfig(), ScreenshotResponseList.class);
return ScreenshotResponseList.to(response);
}
/**
* @param projectId Project Identifier
* @param labelId Label Identifier
* @return Screenshots
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.labels.screenshots.deleteMany" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.labels.screenshots.deleteMany" target="_blank"><b> Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<Screenshot> unassignLabelFromScreenshots(Long projectId, Long labelId, List<Long> screenshotIds) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/labels/%d/screenshots", this.url, projectId, labelId);
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams("screenshotIds", Optional.ofNullable(screenshotIds == null ? null : screenshotIds.stream().map(String::valueOf).collect(Collectors.joining(","))));
ScreenshotResponseList response = this.httpClient.delete(builtUrl, new HttpRequestConfig(queryParams), ScreenshotResponseList.class);
return ScreenshotResponseList.to(response);
}
}