Skip to content

Commit 341e136

Browse files
authored
feat(api): Bundles API: add the includeProjectSourceLanguage property (#173)
1 parent 6061f2d commit 341e136

File tree

7 files changed

+54
-23
lines changed

7 files changed

+54
-23
lines changed

src/main/java/com/crowdin/client/bundles/BundlesApi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public ResponseList<Bundle> listBundles(Long projectId) throws HttpException, Ht
4646
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
4747
* </ul>
4848
*/
49-
public ResponseObject<Bundle> addBundle(Long projectId, Bundle request) throws HttpException, HttpBadRequestException {
49+
public ResponseObject<Bundle> addBundle(Long projectId, AddBundleRequest request) throws HttpException, HttpBadRequestException {
5050
BundleResponseObject response = this.httpClient.post(this.url + "/projects/" + projectId + "/bundles", request, new HttpRequestConfig(), BundleResponseObject.class);
5151
return ResponseObject.of(response.getData());
5252
}
@@ -139,9 +139,9 @@ public ResponseObject<DownloadLink> downloadBundle(Long projectId, Long bundleId
139139
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
140140
* </ul>
141141
*/
142-
public ResponseObject<BundleExport> exportBundle(Long projectId, Long bundleId, Bundle request) throws HttpException, HttpBadRequestException {
142+
public ResponseObject<BundleExport> exportBundle(Long projectId, Long bundleId) throws HttpException, HttpBadRequestException {
143143
BundleExportResponseObject response = this.httpClient.post(this.url + "/projects/" + projectId + "/bundles/" + bundleId + "/exports",
144-
request,
144+
null,
145145
new HttpRequestConfig(),
146146
BundleExportResponseObject.class);
147147
return ResponseObject.of(response.getData());
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.crowdin.client.bundles.model;
2+
3+
import lombok.Data;
4+
5+
import java.util.List;
6+
7+
@Data
8+
public class AddBundleRequest {
9+
private String name;
10+
private String format;
11+
private List<String> sourcePatterns;
12+
private List<String> ignorePatterns;
13+
private String exportPattern;
14+
private Boolean isMultilingual;
15+
private Boolean includeProjectSourceLanguage;
16+
private List<Long> labelIds;
17+
private List<Long> excludeLabelIds;
18+
}

src/main/java/com/crowdin/client/bundles/model/Bundle.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class Bundle {
1515
private List<String> ignorePatterns;
1616
private String exportPattern;
1717
private boolean isMultilingual;
18+
private Boolean includeProjectSourceLanguage;
1819
private List<Long> labelIds;
1920
private Date createdAt;
2021
private Date updatedAt;

src/test/java/com/crowdin/client/bundles/BundlesApiTest.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
import org.apache.http.client.methods.HttpPost;
1717
import org.junit.jupiter.api.Test;
1818

19+
import java.util.ArrayList;
1920
import java.util.Arrays;
21+
import java.util.Calendar;
2022
import java.util.Collections;
23+
import java.util.Date;
2124
import java.util.List;
2225
import java.util.TimeZone;
23-
import java.util.Date;
24-
import java.util.Calendar;
2526

2627
import static org.junit.jupiter.api.Assertions.*;
2728

@@ -51,7 +52,7 @@ public List<RequestMock> getMocks() {
5152
RequestMock.build(this.url + "/projects/" + projectId + "/bundles/" + fileInfoCollectionResourceId + "/files", HttpGet.METHOD_NAME, "api/bundles/fileInfoCollectionResource.json"),
5253
RequestMock.build(this.url + "/projects/" + projectId2 + "/bundles/" + fileCollectionResourceId + "/files", HttpGet.METHOD_NAME, "api/bundles/fileCollectionResource.json"),
5354
RequestMock.build(this.url + "/projects/" + projectId + "/bundles/" + bundleId + "/exports/" + exportId + "/download", HttpGet.METHOD_NAME, "api/bundles/downloadBundle.json"),
54-
RequestMock.build(this.url + "/projects/" + projectId + "/bundles/" + bundleId + "/exports", HttpPost.METHOD_NAME, "api/bundles/addBundleRequest.json", "api/bundles/exportBundle.json"),
55+
RequestMock.build(this.url + "/projects/" + projectId + "/bundles/" + bundleId + "/exports", HttpPost.METHOD_NAME, "api/bundles/exportBundle.json"),
5556
RequestMock.build(this.url + "/projects/" + projectId + "/bundles/" + bundleId + "/exports/" + exportId, HttpGet.METHOD_NAME, "api/bundles/exportBundle.json")
5657
);
5758
}
@@ -67,13 +68,14 @@ public void listBundlesTest() {
6768

6869
@Test
6970
public void addBundleTest() {
70-
Bundle request = new Bundle();
71+
AddBundleRequest request = new AddBundleRequest();
7172
request.setName(name);
7273
request.setFormat(format);
7374
request.setSourcePatterns(Collections.singletonList("/master/"));
7475
request.setIgnorePatterns(Collections.singletonList("/master/environments/"));
7576
request.setExportPattern(pattern);
76-
request.setMultilingual(true);
77+
request.setIsMultilingual(true);
78+
request.setIncludeProjectSourceLanguage(true);
7779
request.setLabelIds(Collections.singletonList(0L));
7880

7981
ResponseObject<Bundle> response = this.getBundlesApi().addBundle(projectId, request);
@@ -89,6 +91,7 @@ public void getBundleTest() {
8991
assertEquals(response.getData().getId(), projectId);
9092
assertEquals(response.getData().getName(), name);
9193
assertTrue(response.getData().isMultilingual());
94+
assertTrue(response.getData().getIncludeProjectSourceLanguage());
9295
}
9396

9497
@Test
@@ -98,10 +101,20 @@ public void deleteBundleTest() {
98101

99102
@Test
100103
public void editBundleTest() {
101-
PatchRequest request = new PatchRequest();
102-
request.setOp(PatchOperation.REPLACE);
103-
request.setPath("/name");
104-
ResponseObject<Bundle> response = this.getBundlesApi().editBundle(projectId, bundleId, Arrays.asList(request));
104+
List<PatchRequest> request = new ArrayList<PatchRequest>() {{
105+
add(new PatchRequest() {{
106+
setOp(PatchOperation.REPLACE);
107+
setPath("/name");
108+
setValue("New name");
109+
}});
110+
add(new PatchRequest() {{
111+
setOp(PatchOperation.REPLACE);
112+
setPath("/includeProjectSourceLanguage");
113+
setValue(true);
114+
}});
115+
}};
116+
117+
ResponseObject<Bundle> response = this.getBundlesApi().editBundle(projectId, bundleId, request);
105118
assertEquals(response.getData().getId(), projectId);
106119
assertEquals(response.getData().getName(), name);
107120
}
@@ -133,16 +146,7 @@ public void downloadBundleTest() {
133146

134147
@Test
135148
public void exportBundleTest() {
136-
Bundle request = new Bundle();
137-
request.setName(name);
138-
request.setFormat(format);
139-
request.setSourcePatterns(Collections.singletonList("/master/"));
140-
request.setIgnorePatterns(Collections.singletonList("/master/environments/"));
141-
request.setExportPattern(pattern);
142-
request.setMultilingual(true);
143-
request.setLabelIds(Collections.singletonList(0L));
144-
145-
ResponseObject<BundleExport> response = this.getBundlesApi().exportBundle(projectId, bundleId, request);
149+
ResponseObject<BundleExport> response = this.getBundlesApi().exportBundle(projectId, bundleId);
146150
assertEquals(exportId, response.getData().getIdentifier());
147151
assertEquals(2,response.getData().getAttributes().getBundleId());
148152
}

src/test/resources/api/bundles/addBundleRequest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
],
1010
"exportPattern": "strings-%two_letter_code%.resx",
1111
"isMultilingual": true,
12+
"includeProjectSourceLanguage": true,
1213
"labelIds": [
1314
0
1415
]

src/test/resources/api/bundles/bundle.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
],
1212
"exportPattern": "strings-%two_letters_code%.resx",
1313
"isMultilingual": true,
14+
"includeProjectSourceLanguage": true,
1415
"labelIds": [
1516
0
1617
],
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
[
22
{
33
"op": "replace",
4-
"path": "/name"
4+
"path": "/name",
5+
"value": "New name"
6+
},
7+
{
8+
"op": "replace",
9+
"path": "/includeProjectSourceLanguage",
10+
"value": true
511
}
612
]

0 commit comments

Comments
 (0)