Skip to content

Commit

Permalink
strings api
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ committed Nov 24, 2023
1 parent de5dfe7 commit e0434c6
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
import com.crowdin.client.core.model.ResponseList;
import com.crowdin.client.core.model.ResponseObject;
import com.crowdin.client.sourcestrings.model.AddSourceStringRequest;
import com.crowdin.client.sourcestrings.model.AddSourceStringStringsBasedRequest;
import com.crowdin.client.sourcestrings.model.SourceString;
import com.crowdin.client.sourcestrings.model.SourceStringResponseList;
import com.crowdin.client.sourcestrings.model.SourceStringResponseObject;
import com.crowdin.client.sourcestrings.model.UploadStringsProgress;
import com.crowdin.client.sourcestrings.model.UploadStringsProgressResponseObject;
import com.crowdin.client.sourcestrings.model.UploadStringsRequest;

import java.util.List;
import java.util.Map;
Expand All @@ -27,6 +31,20 @@ public SourceStringsApi(Credentials credentials, ClientConfig clientConfig) {
super(credentials, clientConfig);
}

/**
* @param projectId project identifier
* @param uploadId upload identifier
*/
public ResponseObject<UploadStringsProgress> uploadStringsStatus(Long projectId, String uploadId) throws HttpException, HttpBadRequestException {
UploadStringsProgressResponseObject stringsProgressResponseObject = this.httpClient.get(this.url + "/projects/" + projectId + "/strings/uploads/" + uploadId, new HttpRequestConfig(), UploadStringsProgressResponseObject.class);
return ResponseObject.of(stringsProgressResponseObject.getData());
}

public ResponseObject<UploadStringsProgress> uploadStrings(Long projectId, UploadStringsRequest request) throws HttpException, HttpBadRequestException {
UploadStringsProgressResponseObject stringsProgressResponseObject = this.httpClient.post(this.url + "/projects/" + projectId + "/strings/uploads", request, new HttpRequestConfig(), UploadStringsProgressResponseObject.class);
return ResponseObject.of(stringsProgressResponseObject.getData());
}

/**
* @param projectId project identifier
* @param fileId file identifier
Expand Down Expand Up @@ -74,6 +92,11 @@ public ResponseObject<SourceString> addSourceString(Long projectId, AddSourceStr
return ResponseObject.of(sourceStringResponseObject.getData());
}

public ResponseObject<SourceString> addSourceStringStringsBased(Long projectId, AddSourceStringStringsBasedRequest request) throws HttpException, HttpBadRequestException {
SourceStringResponseObject sourceStringResponseObject = this.httpClient.post(this.url + "/projects/" + projectId + "/strings", request, new HttpRequestConfig(), SourceStringResponseObject.class);
return ResponseObject.of(sourceStringResponseObject.getData());
}

/**
* @param projectId project identifier
* @param stringId string identifier
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.crowdin.client.sourcestrings.model;

import lombok.Data;

import java.util.List;

@Data
public class AddSourceStringStringsBasedRequest {

private String text;
private String identifier;
private Long branchId;
private String context;
private Boolean isHidden;
private Integer maxLength;
private List<Long> labelIds;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.crowdin.client.sourcestrings.model;

import lombok.Data;

@Data
public class ImportOptions {

private Boolean firstLineContainsHeader;
private Boolean importTranslations;
private Object scheme;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.crowdin.client.sourcestrings.model;

import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
public class UploadStringsProgress {

private String identifier;
private String status;
private int progress;
private Attributes attributes;
private Date createdAt;
private Date updatedAt;
private Date startedAt;
private Date finishedAt;
private String eta;

@Data
public static class Attributes {
private Long branchId;
private Long storageId;
private String fileType;
private Integer parserVersion;
private List<Long> labelIds;
private ImportOptions importOptions;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.crowdin.client.sourcestrings.model;

import lombok.Data;

@Data
public class UploadStringsProgressResponseObject {

private UploadStringsProgress data;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.crowdin.client.sourcestrings.model;

import lombok.Data;

import java.util.List;

@Data
public class UploadStringsRequest {

private Long branchId;
private Long storageId;
private String type;
private Integer parserVersion;
private List<Long> labelIds;
private Boolean updateStrings;
private Boolean cleanupMode;
private ImportOptions importOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import com.crowdin.client.framework.RequestMock;
import com.crowdin.client.framework.TestClient;
import com.crowdin.client.sourcestrings.model.AddSourceStringRequest;
import com.crowdin.client.sourcestrings.model.AddSourceStringStringsBasedRequest;
import com.crowdin.client.sourcestrings.model.SourceString;
import com.crowdin.client.sourcestrings.model.SourceStringForm;
import com.crowdin.client.sourcestrings.model.UploadStringsProgress;
import com.crowdin.client.sourcestrings.model.UploadStringsRequest;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPatch;
Expand All @@ -31,19 +34,47 @@ public class SourceStringsApiTest extends TestClient {
private final Long projectId = 3L;
private final Long id = 2814L;
private final Long branchId = 667L;
private final Long storageId = 61L;
private final Long labelId = 1L;
private final String uploadId = "50fb3506-4127-4ba8-8296-f97dc7e3e0c3";

@Override
public List<RequestMock> getMocks() {
return Arrays.asList(
RequestMock.build(this.url + "/projects/" + projectId + "/strings/uploads/" + uploadId, HttpGet.METHOD_NAME, "api/strings/uploadStrings.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/strings/uploads", HttpPost.METHOD_NAME, "api/strings/uploadStringsReq.json", "api/strings/uploadStrings.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/strings", HttpGet.METHOD_NAME, "api/strings/listStrings.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/strings", HttpGet.METHOD_NAME, "api/strings/listStrings.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/strings", HttpPost.METHOD_NAME, "api/strings/addStringRequest.json", "api/strings/string.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/strings", HttpPost.METHOD_NAME, "api/strings/addStringStringsBasedRequest.json", "api/strings/string.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/strings/" + id, HttpGet.METHOD_NAME, "api/strings/string.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/strings/" + id, HttpDelete.METHOD_NAME),
RequestMock.build(this.url + "/projects/" + projectId + "/strings/" + id, HttpPatch.METHOD_NAME, "api/strings/editString.json", "api/strings/string.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/strings", HttpPatch.METHOD_NAME, "api/strings/stringBatchOperationsRequest.json", "api/strings/listStrings.json")
);
}

@Test
public void uploadStringsStatusTest() {
ResponseObject<UploadStringsProgress> uploadStringsProgressResponseObject = this.getSourceStringsApi().uploadStringsStatus(projectId, uploadId);
assertEquals(uploadStringsProgressResponseObject.getData().getIdentifier(), uploadId);
assertEquals(uploadStringsProgressResponseObject.getData().getAttributes().getBranchId(), branchId);
assertEquals(uploadStringsProgressResponseObject.getData().getAttributes().getStorageId(), storageId);
assertEquals(uploadStringsProgressResponseObject.getData().getAttributes().getLabelIds().get(0), labelId);
}

@Test
public void uploadStringsTest() {
UploadStringsRequest request = new UploadStringsRequest();
request.setBranchId(branchId);
request.setStorageId(storageId);
request.setLabelIds(singletonList(labelId));
ResponseObject<UploadStringsProgress> uploadStringsProgressResponseObject = this.getSourceStringsApi().uploadStrings(projectId, request);
assertEquals(uploadStringsProgressResponseObject.getData().getIdentifier(), uploadId);
assertEquals(uploadStringsProgressResponseObject.getData().getAttributes().getBranchId(), branchId);
assertEquals(uploadStringsProgressResponseObject.getData().getAttributes().getLabelIds().get(0), labelId);
}

@Test
public void listStringsTest() {
ResponseList<SourceString> sourceStringResponseList = this.getSourceStringsApi().listSourceStrings(projectId, null, null, null, null, null, null, null, null, null);
Expand All @@ -70,6 +101,21 @@ public void addStringTest() {
assertEquals(sourceStringResponseObject.getData().getText(), text);
}

@Test
public void addStringStringsBasedTest() {
AddSourceStringStringsBasedRequest request = new AddSourceStringStringsBasedRequest();
request.setText(text);
request.setIdentifier("6a1821e6499ebae94de4b880fd93b985");
request.setBranchId(branchId);
request.setContext("shown on main page");
request.setIsHidden(false);
request.setMaxLength(35);
request.setLabelIds(Arrays.asList(1L));
ResponseObject<SourceString> sourceStringResponseObject = this.getSourceStringsApi().addSourceStringStringsBased(projectId, request);
assertEquals(sourceStringResponseObject.getData().getId(), id);
assertEquals(sourceStringResponseObject.getData().getText(), text);
}

@Test
public void getStringTest() {
ResponseObject<SourceString> sourceStringResponseObject = this.getSourceStringsApi().getSourceString(projectId, id);
Expand Down
11 changes: 11 additions & 0 deletions src/test/resources/api/strings/addStringStringsBasedRequest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"text": "Not all videos are shown to users. See more",
"identifier": "6a1821e6499ebae94de4b880fd93b985",
"branchId": 667,
"context": "shown on main page",
"isHidden": false,
"maxLength": 35,
"labelIds": [
1
]
}
32 changes: 32 additions & 0 deletions src/test/resources/api/strings/uploadStrings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"data": {
"identifier": "50fb3506-4127-4ba8-8296-f97dc7e3e0c3",
"status": "finished",
"progress": 100,
"attributes": {
"branchId": 667,
"storageId": 61,
"fileType": "android",
"parserVersion": 8,
"labelIds": [
1
],
"importOptions": {
"firstLineContainsHeader": false,
"importTranslations": true,
"scheme": {
"identifier": 0,
"sourcePhrase": 1,
"en": 2,
"de": 3
}
},
"updateStrings": false,
"cleanupMode": false
},
"createdAt": "2019-09-23T11:26:54+00:00",
"updatedAt": "2019-09-23T11:26:54+00:00",
"startedAt": "2019-09-23T11:26:54+00:00",
"finishedAt": "2019-09-23T11:26:54+00:00"
}
}
7 changes: 7 additions & 0 deletions src/test/resources/api/strings/uploadStringsReq.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"storageId": 61,
"branchId": 667,
"labelIds": [
1
]
}

0 comments on commit e0434c6

Please sign in to comment.