Skip to content

Commit 5ab9f0c

Browse files
feat: add support to Remove String Approvals endpoint (#310)
1 parent ea0ee96 commit 5ab9f0c

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/main/java/com/crowdin/client/stringtranslations/StringTranslationsApi.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ public ResponseObject<Approval> getApproval(Long projectId, Long approvalId) thr
106106
return ResponseObject.of(storageResponseObject.getData());
107107
}
108108

109+
/**
110+
* @param projectId project identifier
111+
* @param stringId string identifier
112+
* @see <ul>
113+
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.approvals.deleteMany" target="_blank"><b>API Documentation</b></a></li>
114+
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.approvals.deleteMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
115+
* </ul>
116+
*/
117+
public void removeStringApprovals(Long projectId, Long stringId) throws HttpException, HttpBadRequestException {
118+
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
119+
"stringId", Optional.of(stringId)
120+
);
121+
this.httpClient.delete(this.url + "/projects/" + projectId + "/approvals", new HttpRequestConfig(queryParams), Void.class);
122+
}
123+
109124
/**
110125
* @param projectId project identifier
111126
* @param approvalId approval identifier
@@ -228,10 +243,10 @@ public ResponseObject<StringTranslation> addTranslation(Long projectId, AddStrin
228243
*/
229244
public void deleteStringTranslations(Long projectId, Long stringId, String languageId) throws HttpException, HttpBadRequestException {
230245
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
231-
"stringId", Optional.ofNullable(stringId),
246+
"stringId", Optional.of(stringId),
232247
"languageId", Optional.ofNullable(languageId)
233248
);
234-
this.httpClient.get(this.url + "/projects/" + projectId + "/translations", new HttpRequestConfig(queryParams), Void.class);
249+
this.httpClient.delete(this.url + "/projects/" + projectId + "/translations", new HttpRequestConfig(queryParams), Void.class);
235250
}
236251

237252
/**

src/test/java/com/crowdin/client/stringtranslations/StringTranslationsApiTest.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import java.util.Arrays;
1515
import java.util.List;
16+
import java.util.Collections;
1617

1718
import static org.junit.jupiter.api.Assertions.assertEquals;
1819
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -35,13 +36,14 @@ public List<RequestMock> getMocks() {
3536
RequestMock.build(this.url + "/projects/" + projectId + "/approvals", HttpGet.METHOD_NAME, "api/stringtranslations/listApprovals.json"),
3637
RequestMock.build(this.url + "/projects/" + projectId + "/approvals", HttpPost.METHOD_NAME, "api/stringtranslations/addApprovalRequest.json", "api/stringtranslations/approval.json"),
3738
RequestMock.build(this.url + "/projects/" + projectId + "/approvals/" + approvalId, HttpGet.METHOD_NAME, "api/stringtranslations/approval.json"),
39+
RequestMock.build(this.url + "/projects/" + projectId + "/approvals", HttpDelete.METHOD_NAME, null, Collections.singletonMap("stringId", stringId)),
3840
RequestMock.build(this.url + "/projects/" + projectId + "/approvals/" + approvalId, HttpDelete.METHOD_NAME),
3941
RequestMock.build(String.format("%s/projects/%d/languages/%s/translations", this.url, projectId, language), HttpGet.METHOD_NAME, "api/stringtranslations/listLanguageTranslations_plain.json"),
4042
RequestMock.build(String.format("%s/projects/%d/languages/%s/translations", this.url, secondProjectId, language), HttpGet.METHOD_NAME, "api/stringtranslations/listLanguageTranslations_plural.json"),
4143
RequestMock.build(String.format("%s/projects/%d/languages/%s/translations", this.url, thirdProjectId, language), HttpGet.METHOD_NAME, "api/stringtranslations/listLanguageTranslations_ICU.json"),
4244
RequestMock.build(this.url + "/projects/" + projectId + "/translations", HttpGet.METHOD_NAME, "api/stringtranslations/listStringTranslations..json"),
4345
RequestMock.build(this.url + "/projects/" + projectId + "/translations", HttpPost.METHOD_NAME, "api/stringtranslations/addTranslationRequest.json", "api/stringtranslations/translation.json"),
44-
RequestMock.build(this.url + "/projects/" + projectId + "/translations", HttpDelete.METHOD_NAME),
46+
RequestMock.build(this.url + "/projects/" + projectId + "/translations", HttpDelete.METHOD_NAME, null, Collections.singletonMap("stringId", stringId)),
4547
RequestMock.build(this.url + "/projects/" + projectId + "/translations/" + translationId, HttpGet.METHOD_NAME, "api/stringtranslations/translation.json"),
4648
RequestMock.build(this.url + "/projects/" + projectId + "/translations/" + translationId, HttpDelete.METHOD_NAME),
4749
RequestMock.build(this.url + "/projects/" + projectId + "/translations/" + translationId, HttpPut.METHOD_NAME, "api/stringtranslations/translation.json"),
@@ -86,6 +88,11 @@ public void getApprovalTest() {
8688
assertEquals(approvalResponseObject.getData().getId(), approvalId);
8789
}
8890

91+
@Test
92+
public void removeStringApprovalsTest() {
93+
this.getStringTranslationsApi().removeStringApprovals(projectId, stringId);
94+
}
95+
8996
@Test
9097
public void removeApprovalTest() {
9198
this.getStringTranslationsApi().removeApproval(projectId, approvalId);
@@ -134,7 +141,7 @@ public void addTranslationTest() {
134141

135142
@Test
136143
public void deleteTranslationsTest() {
137-
this.getStringTranslationsApi().deleteStringTranslations(projectId, null, null);
144+
this.getStringTranslationsApi().deleteStringTranslations(projectId, stringId, null);
138145
}
139146

140147
@Test

0 commit comments

Comments
 (0)