-
Notifications
You must be signed in to change notification settings - Fork 68
feat: add Style Guides API #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andrii-bodnar
merged 4 commits into
crowdin:master
from
bulat3103:feature/add_styles_guides_api
Mar 25, 2026
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/main/java/com/crowdin/client/styleguide/StyleGuidesApi.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| package com.crowdin.client.styleguide; | ||
|
|
||
| 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.styleguide.model.*; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
|
||
| public class StyleGuidesApi extends CrowdinApi { | ||
| public StyleGuidesApi(Credentials credentials) { | ||
| super(credentials); | ||
| } | ||
|
|
||
| public StyleGuidesApi(Credentials credentials, ClientConfig clientConfig) { | ||
| super(credentials, clientConfig); | ||
| } | ||
|
|
||
| /** | ||
| * @param styleGuideId style guide identifier | ||
| * @see <ul> | ||
| * <li><a href="https://developer.crowdin.com/api/v2/#operation/api.style-guides.delete" target="_blank"><b>API Documentation</b></a></li> | ||
| * <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.style-guides.delete" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
| * </ul> | ||
| */ | ||
| public void deleteStyleGuide(Long styleGuideId) throws HttpException, HttpBadRequestException { | ||
| this.httpClient.delete(this.url + "/style-guides/" + styleGuideId, new HttpRequestConfig(), Void.class); | ||
| } | ||
|
|
||
| /** | ||
| * @param styleGuideId style guide identifier | ||
| * @param request request object | ||
| * @return updated style guide | ||
| * @see <ul> | ||
| * <li><a href="https://developer.crowdin.com/api/v2/#operation/api.style-guides.patch" target="_blank"><b>API Documentation</b></a></li> | ||
| * <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.style-guides.patch" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
| * </ul> | ||
| */ | ||
| public ResponseObject<StyleGuide> editStyleGuide(Long styleGuideId, List<PatchRequest> request) throws HttpException, HttpBadRequestException { | ||
| StyleGuideResponseObject styleGuideResponseObject = this.httpClient.patch(this.url + "/style-guides/" + styleGuideId, request, new HttpRequestConfig(), StyleGuideResponseObject.class); | ||
| return ResponseObject.of(styleGuideResponseObject.getData()); | ||
| } | ||
|
|
||
| /** | ||
| * @param styleGuideId style guide identifier | ||
| * @return style guide | ||
| * @see <ul> | ||
| * <li><a href="https://developer.crowdin.com/api/v2/#operation/api.style-guides.get" target="_blank"><b>API Documentation</b></a></li> | ||
| * <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.style-guides.get" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
| * </ul> | ||
| */ | ||
| public ResponseObject<StyleGuide> getStyleGuide(Long styleGuideId) throws HttpException, HttpBadRequestException { | ||
| StyleGuideResponseObject styleGuideResponseObject = this.httpClient.get(this.url + "/style-guides/" + styleGuideId, new HttpRequestConfig(), StyleGuideResponseObject.class); | ||
| return ResponseObject.of(styleGuideResponseObject.getData()); | ||
| } | ||
|
|
||
| /** | ||
| * @param request request object | ||
| * @return newly created style guide | ||
| * @see <ul> | ||
| * <li><a href="https://developer.crowdin.com/api/v2/#operation/api.style-guides.post" target="_blank"><b>API Documentation</b></a></li> | ||
| * <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.style-guides.post" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
| * </ul> | ||
| */ | ||
| public ResponseObject<StyleGuide> addStyleGuide(AddStyleGuideRequest request) throws HttpException, HttpBadRequestException { | ||
| StyleGuideResponseObject styleGuideResponseObject = this.httpClient.post(this.url + "/style-guides", request, new HttpRequestConfig(), StyleGuideResponseObject.class); | ||
| return ResponseObject.of(styleGuideResponseObject.getData()); | ||
| } | ||
|
|
||
| /** | ||
| * @param userId user identifier | ||
| * @param limit maximum number of items to retrieve (default 25) | ||
| * @param offset starting offset in the collection (default 0) | ||
| * @return list of style guides | ||
| * @see <ul> | ||
| * <li><a href="https://developer.crowdin.com/api/v2/#operation/api.style-guides.getMany" target="_blank"><b>API Documentation</b></a></li> | ||
| * <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.style-guides.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
| * </ul> | ||
| */ | ||
| public ResponseList<StyleGuide> listStyleGuide(Long userId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException { | ||
| ListStyleGuidesParams params = new ListStyleGuidesParams(); | ||
| params.setUserId(userId); | ||
| params.setLimit(limit); | ||
| params.setOffset(offset); | ||
| return listStyleGuide(params); | ||
| } | ||
|
|
||
| /** | ||
| * @param userId user identifier | ||
| * @param limit maximum number of items to retrieve (default 25) | ||
| * @param offset starting offset in the collection (default 0) | ||
| * @param orderBy list of OrderByField | ||
| * @return list of style guides | ||
| * @see <ul> | ||
| * <li><a href="https://developer.crowdin.com/api/v2/#operation/api.style-guides.getMany" target="_blank"><b>API Documentation</b></a></li> | ||
| * <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.style-guides.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
| * </ul> | ||
| */ | ||
| public ResponseList<StyleGuide> listStyleGuide(Long userId, Integer limit, Integer offset, List<OrderByField> orderBy) throws HttpException, HttpBadRequestException { | ||
| ListStyleGuidesParams params = new ListStyleGuidesParams(); | ||
| params.setUserId(userId); | ||
| params.setLimit(limit); | ||
| params.setOffset(offset); | ||
| params.setOrderByList(orderBy); | ||
| return listStyleGuide(params); | ||
| } | ||
|
|
||
| public ResponseList<StyleGuide> listStyleGuide(ListStyleGuidesParams params) { | ||
| ListStyleGuidesParams query = Optional.ofNullable(params).orElse(new ListStyleGuidesParams()); | ||
|
|
||
| String orderBy = query.getOrderByList() != null | ||
| ? OrderByField.generateSortParam(query.getOrderByList()) | ||
| : query.getOrderBy(); | ||
|
|
||
| Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams( | ||
| "userId", Optional.ofNullable(query.getUserId()), | ||
| "limit", Optional.ofNullable(query.getLimit()), | ||
| "offset", Optional.ofNullable(query.getOffset()), | ||
| "orderBy", Optional.ofNullable(orderBy) | ||
| ); | ||
| StyleGuideResponseList styleGuideResponseList = this.httpClient.get(this.url + "/style-guides", new HttpRequestConfig(queryParams), StyleGuideResponseList.class); | ||
| return StyleGuideResponseList.to(styleGuideResponseList); | ||
| } | ||
|
bulat3103 marked this conversation as resolved.
Outdated
|
||
| } | ||
15 changes: 15 additions & 0 deletions
15
src/main/java/com/crowdin/client/styleguide/model/AddStyleGuideRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.crowdin.client.styleguide.model; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Data | ||
| public class AddStyleGuideRequest { | ||
| private String name; | ||
| private String aiInstructions; | ||
| private List<String> languageIds; | ||
| private List<Long> projectIds; | ||
| private Boolean isShared; | ||
| private Long storageId; | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/crowdin/client/styleguide/model/ListStyleGuidesParams.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.crowdin.client.styleguide.model; | ||
|
|
||
| import com.crowdin.client.core.model.OrderByField; | ||
| import com.crowdin.client.core.model.Pagination; | ||
| import lombok.Data; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Data | ||
| public class ListStyleGuidesParams extends Pagination { | ||
| private Long userId; | ||
| private String orderBy; | ||
| private List<OrderByField> orderByList; | ||
| } |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/crowdin/client/styleguide/model/StyleGuide.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.crowdin.client.styleguide.model; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| import java.util.Date; | ||
| import java.util.List; | ||
|
|
||
| @Data | ||
| public class StyleGuide { | ||
| private Long id; | ||
| private String name; | ||
| private String aiInstructions; | ||
| private Long userId; | ||
| private List<String> languageIds; | ||
| private List<Long> projectIds; | ||
| private Boolean isShared; | ||
| private String webUrl; | ||
| private String downloadLink; | ||
| private Date createdAt; | ||
| private Date updatedAt; | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/crowdin/client/styleguide/model/StyleGuideResponseList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.crowdin.client.styleguide.model; | ||
|
|
||
| import com.crowdin.client.core.model.Pagination; | ||
| import com.crowdin.client.core.model.ResponseList; | ||
| import com.crowdin.client.core.model.ResponseObject; | ||
| import lombok.Data; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @Data | ||
| public class StyleGuideResponseList { | ||
| private List<StyleGuideResponseObject> data; | ||
| private Pagination pagination; | ||
|
|
||
| public static ResponseList<StyleGuide> to(StyleGuideResponseList styleGuideResponseList) { | ||
| return ResponseList.of( | ||
| styleGuideResponseList.getData().stream() | ||
| .map(StyleGuideResponseObject::getData) | ||
| .map(ResponseObject::of) | ||
| .collect(Collectors.toList()), | ||
| styleGuideResponseList.getPagination() | ||
| ); | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/crowdin/client/styleguide/model/StyleGuideResponseObject.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.crowdin.client.styleguide.model; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| public class StyleGuideResponseObject { | ||
| private StyleGuide data; | ||
| } |
88 changes: 88 additions & 0 deletions
88
src/test/java/com/crowdin/client/styleguide/StyleGuidesApiTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package com.crowdin.client.styleguide; | ||
|
|
||
| import com.crowdin.client.core.model.PatchOperation; | ||
| import com.crowdin.client.core.model.PatchRequest; | ||
| import com.crowdin.client.core.model.ResponseList; | ||
| import com.crowdin.client.core.model.ResponseObject; | ||
| import com.crowdin.client.framework.RequestMock; | ||
| import com.crowdin.client.framework.TestClient; | ||
| import com.crowdin.client.styleguide.model.AddStyleGuideRequest; | ||
| import com.crowdin.client.styleguide.model.StyleGuide; | ||
| import org.apache.http.client.methods.HttpDelete; | ||
| import org.apache.http.client.methods.HttpGet; | ||
| import org.apache.http.client.methods.HttpPatch; | ||
| import org.apache.http.client.methods.HttpPost; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import static java.util.Collections.singletonList; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| public class StyleGuidesApiTest extends TestClient { | ||
|
|
||
| private final Long styleGuideId = 2L; | ||
| private final Long storageId = 1L; | ||
| private final String name = "Be My Eyes iOS's Style Guide"; | ||
| private final String aiInstructions = "string"; | ||
| private final List<String> languageIds = Arrays.asList("uk", "fr", "de"); | ||
| private final List<Long> projectIds = Arrays.asList(1L, 2L, 3L); | ||
| private final Boolean isShared = false; | ||
|
|
||
| @Override | ||
| public List<RequestMock> getMocks() { | ||
| return Arrays.asList( | ||
| RequestMock.build(this.url + "/style-guides", HttpGet.METHOD_NAME, "api/styleguide/listStyleGuides.json"), | ||
| RequestMock.build(this.url + "/style-guides", HttpPost.METHOD_NAME, "api/styleguide/addStyleGuideRequest.json", "api/styleguide/styleGuide.json"), | ||
| RequestMock.build(this.url + "/style-guides/" + styleGuideId, HttpGet.METHOD_NAME, "api/styleguide/styleGuide.json"), | ||
| RequestMock.build(this.url + "/style-guides/" + styleGuideId, HttpDelete.METHOD_NAME), | ||
| RequestMock.build(this.url + "/style-guides/" + styleGuideId, HttpPatch.METHOD_NAME, "api/styleguide/editStyleGuide.json", "api/styleguide/styleGuide.json") | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void listStyleGuidesTest() { | ||
| ResponseList<StyleGuide> styleGuideResponseList = this.getStyleGuidesApi().listStyleGuide(null, null, null); | ||
| assertEquals(styleGuideResponseList.getData().size(), 1); | ||
| assertEquals(styleGuideResponseList.getData().get(0).getData().getId(), styleGuideId); | ||
| assertEquals(styleGuideResponseList.getData().get(0).getData().getName(), name); | ||
| } | ||
|
|
||
| @Test | ||
| public void addStyleGuideTest() { | ||
| AddStyleGuideRequest request = new AddStyleGuideRequest(); | ||
| request.setName(name); | ||
| request.setAiInstructions(aiInstructions); | ||
| request.setLanguageIds(languageIds); | ||
| request.setProjectIds(projectIds); | ||
| request.setIsShared(isShared); | ||
| request.setStorageId(storageId); | ||
| ResponseObject<StyleGuide> styleGuideResponseObject = this.getStyleGuidesApi().addStyleGuide(request); | ||
| assertEquals(styleGuideResponseObject.getData().getId(), styleGuideId); | ||
| assertEquals(styleGuideResponseObject.getData().getName(), name); | ||
| } | ||
|
|
||
| @Test | ||
| public void getStyleGuideTest() { | ||
| ResponseObject<StyleGuide> styleGuideResponseObject = this.getStyleGuidesApi().getStyleGuide(styleGuideId); | ||
| assertEquals(styleGuideResponseObject.getData().getId(), styleGuideId); | ||
| assertEquals(styleGuideResponseObject.getData().getName(), name); | ||
| } | ||
|
bulat3103 marked this conversation as resolved.
|
||
|
|
||
| @Test | ||
| public void deleteStyleGuideTest() { | ||
| this.getStyleGuidesApi().deleteStyleGuide(styleGuideId); | ||
| } | ||
|
|
||
| @Test | ||
| public void editStyleGuideTest() { | ||
| PatchRequest request = new PatchRequest(); | ||
| request.setOp(PatchOperation.REPLACE); | ||
| request.setValue(name); | ||
| request.setPath("/name"); | ||
| ResponseObject<StyleGuide> styleGuideResponseObject = this.getStyleGuidesApi().editStyleGuide(styleGuideId, singletonList(request)); | ||
| assertEquals(styleGuideResponseObject.getData().getId(), styleGuideId); | ||
| assertEquals(styleGuideResponseObject.getData().getName(), name); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "name": "Be My Eyes iOS's Style Guide", | ||
| "aiInstructions": "string", | ||
| "languageIds": ["uk", "fr", "de"], | ||
| "projectIds": [1, 2, 3], | ||
| "isShared": false, | ||
| "storageId": 1 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [ | ||
| { | ||
| "op": "replace", | ||
| "path": "/name", | ||
| "value": "Be My Eyes iOS's Style Guide" | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "data": { | ||
| "id": 2, | ||
| "name": "Be My Eyes iOS's Style Guide", | ||
| "aiInstructions": "string", | ||
| "userId": 2, | ||
| "languageId": ["uk", "fr", "de"], | ||
|
bulat3103 marked this conversation as resolved.
Outdated
|
||
| "projectIds": [1, 2, 3], | ||
| "isShared": false, | ||
| "createdAt": "2019-09-16T13:42:04+00:00" | ||
| } | ||
| } | ||
| ], | ||
| "pagination": { | ||
| "offset": 0, | ||
| "limit": 25 | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "data": { | ||
| "id": 2, | ||
| "name": "Be My Eyes iOS's Style Guide", | ||
| "aiInstructions": "string", | ||
| "userId": 2, | ||
| "languageId": ["uk", "fr", "de"], | ||
|
bulat3103 marked this conversation as resolved.
Outdated
|
||
| "projectIds": [1, 2, 3], | ||
| "isShared": false, | ||
| "createdAt": "2019-09-16T13:42:04+00:00" | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.