Skip to content

Commit

Permalink
Adding assignLabelToScreenshots & unassignLabelToScreenshots api
Browse files Browse the repository at this point in the history
  • Loading branch information
Durdush committed Jul 24, 2023
1 parent 5961f46 commit 5f0a82f
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 13 deletions.
30 changes: 30 additions & 0 deletions src/main/java/com/crowdin/client/labels/LabelsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
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;

Expand Down Expand Up @@ -141,5 +144,32 @@ public ResponseList<SourceString> unassignLabelFromStrings(Long projectId, Long
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>
* </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>
* </ul>
*/
public ResponseList<Screenshot> unassignLabelFromScreenshots(Long projectId, Long labelId) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/labels/%d/screenshots", this.url, projectId, labelId);
ScreenshotResponseList response = this.httpClient.delete(builtUrl, new HttpRequestConfig(), ScreenshotResponseList.class);
return ScreenshotResponseList.to(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.crowdin.client.labels.model;

import lombok.Data;

import java.util.List;

@Data
public class LabelToScreenshotsRequest {

private List<Long> screenshotIds;
}
46 changes: 33 additions & 13 deletions src/test/java/com/crowdin/client/labels/LabelsApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import com.crowdin.client.framework.TestClient;
import com.crowdin.client.labels.model.AddLabelRequest;
import com.crowdin.client.labels.model.Label;
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.sourcestrings.model.SourceString;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
Expand Down Expand Up @@ -37,19 +39,23 @@ private String file(String fileName) {
@Override
public List<RequestMock> getMocks() {
return Arrays.asList(
RequestMock.build(String.format("%s/projects/%d/labels", this.url, projectId), HttpGet.METHOD_NAME,
"api/labels/listLabels.json"),
RequestMock.build(String.format("%s/projects/%d/labels", this.url, projectId), HttpPost.METHOD_NAME,
"api/labels/addLabelRequest.json", "api/labels/label.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId), HttpGet.METHOD_NAME,
"api/labels/label.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId), HttpDelete.METHOD_NAME),
RequestMock.build(String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId), HttpPatch.METHOD_NAME,
"api/labels/editLabelRequest.json", "api/labels/label.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d/strings", this.url, projectId, labelId), HttpPost.METHOD_NAME,
"api/labels/labelToStringsRequest.json", "api/labels/listStrings.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d/strings", this.url, projectId, labelId), HttpDelete.METHOD_NAME,
"api/labels/listStrings.json")
RequestMock.build(String.format("%s/projects/%d/labels", this.url, projectId), HttpGet.METHOD_NAME,
"api/labels/listLabels.json"),
RequestMock.build(String.format("%s/projects/%d/labels", this.url, projectId), HttpPost.METHOD_NAME,
"api/labels/addLabelRequest.json", "api/labels/label.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId), HttpGet.METHOD_NAME,
"api/labels/label.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId), HttpDelete.METHOD_NAME),
RequestMock.build(String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId), HttpPatch.METHOD_NAME,
"api/labels/editLabelRequest.json", "api/labels/label.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d/strings", this.url, projectId, labelId), HttpPost.METHOD_NAME,
"api/labels/labelToStringsRequest.json", "api/labels/listStrings.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d/strings", this.url, projectId, labelId), HttpDelete.METHOD_NAME,
"api/labels/listStrings.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d/screenshots", this.url, projectId, labelId), HttpPost.METHOD_NAME,
"api/labels/labelToScreenshotsRequest.json", "api/labels/listStrings.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d/screenshots", this.url, projectId, labelId), HttpDelete.METHOD_NAME,
"api/labels/listStrings.json")
);
}

Expand Down Expand Up @@ -111,5 +117,19 @@ public void unassignLabelToStringTest() {
assertEquals(1, response.getData().size());
}

@Test
public void assignLabelToScreenshot() {
LabelToScreenshotsRequest request = new LabelToScreenshotsRequest() {{
setScreenshotIds(Arrays.asList(1L));
}};
ResponseList<Screenshot> response = this.getLabelsApi().assignLabelToScreenshots(projectId, labelId, request);
assertEquals(1, response.getData().size());
}

@Test
public void unassignLabelToScreenshot() {
ResponseList<Screenshot> response = this.getLabelsApi().unassignLabelFromScreenshots(projectId, labelId);
assertEquals(1, response.getData().size());

}
}
5 changes: 5 additions & 0 deletions src/test/resources/api/labels/labelToScreenshotsRequest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"screenshotIds": [
1
]
}
37 changes: 37 additions & 0 deletions src/test/resources/api/labels/listScreenshots.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"data": [
{
"data": {
"id": 1,
"userId": 6,
"url": "https://production-enterprise-screenshots.downloads.crowdin.com/992000002/6/2/middle.jpg?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIGJKLQV66ZXPMMEA%2F20190923%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190923T093016Z&X-Amz-SignedHeaders=host&X-Amz-Expires=120&X-Amz-Signature=8df06f57594f7d1804b7c037629f6916224415e9b935c4f6619fbe002fb25e73",
"name": "translate_with_siri.jpg",
"size": {
"width": 267,
"height": 176
},
"tagsCount": 0,
"tags": [
{
"id": 98,
"screenshotId": 2,
"stringId": 2822,
"position": {
"x": 474,
"y": 147,
"width": 490,
"height": 99
},
"createdAt": "2019-09-23T09:35:31+00:00"
}
],
"createdAt": "2019-09-23T09:29:19+00:00",
"updatedAt": "2019-09-23T09:29:19+00:00"
}
}
],
"pagination": {
"offset": 0,
"limit": 25
}
}

0 comments on commit 5f0a82f

Please sign in to comment.