|
| 1 | +package com.crowdin.client.styleguide; |
| 2 | + |
| 3 | +import com.crowdin.client.core.CrowdinApi; |
| 4 | +import com.crowdin.client.core.http.HttpRequestConfig; |
| 5 | +import com.crowdin.client.core.http.exceptions.HttpBadRequestException; |
| 6 | +import com.crowdin.client.core.http.exceptions.HttpException; |
| 7 | +import com.crowdin.client.core.model.*; |
| 8 | +import com.crowdin.client.styleguide.model.*; |
| 9 | + |
| 10 | +import java.util.List; |
| 11 | +import java.util.Map; |
| 12 | +import java.util.Optional; |
| 13 | + |
| 14 | +public class StyleGuidesApi extends CrowdinApi { |
| 15 | + public StyleGuidesApi(Credentials credentials) { |
| 16 | + super(credentials); |
| 17 | + } |
| 18 | + |
| 19 | + public StyleGuidesApi(Credentials credentials, ClientConfig clientConfig) { |
| 20 | + super(credentials, clientConfig); |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * @param styleGuideId style guide identifier |
| 25 | + * @see <ul> |
| 26 | + * <li><a href="https://developer.crowdin.com/api/v2/#operation/api.style-guides.delete" target="_blank"><b>API Documentation</b></a></li> |
| 27 | + * <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.style-guides.delete" target="_blank"><b>Enterprise API Documentation</b></a></li> |
| 28 | + * </ul> |
| 29 | + */ |
| 30 | + public void deleteStyleGuide(Long styleGuideId) throws HttpException, HttpBadRequestException { |
| 31 | + this.httpClient.delete(this.url + "/style-guides/" + styleGuideId, new HttpRequestConfig(), Void.class); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @param styleGuideId style guide identifier |
| 36 | + * @param request request object |
| 37 | + * @return updated style guide |
| 38 | + * @see <ul> |
| 39 | + * <li><a href="https://developer.crowdin.com/api/v2/#operation/api.style-guides.patch" target="_blank"><b>API Documentation</b></a></li> |
| 40 | + * <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.style-guides.patch" target="_blank"><b>Enterprise API Documentation</b></a></li> |
| 41 | + * </ul> |
| 42 | + */ |
| 43 | + public ResponseObject<StyleGuide> editStyleGuide(Long styleGuideId, List<PatchRequest> request) throws HttpException, HttpBadRequestException { |
| 44 | + StyleGuideResponseObject styleGuideResponseObject = this.httpClient.patch(this.url + "/style-guides/" + styleGuideId, request, new HttpRequestConfig(), StyleGuideResponseObject.class); |
| 45 | + return ResponseObject.of(styleGuideResponseObject.getData()); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @param styleGuideId style guide identifier |
| 50 | + * @return style guide |
| 51 | + * @see <ul> |
| 52 | + * <li><a href="https://developer.crowdin.com/api/v2/#operation/api.style-guides.get" target="_blank"><b>API Documentation</b></a></li> |
| 53 | + * <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.style-guides.get" target="_blank"><b>Enterprise API Documentation</b></a></li> |
| 54 | + * </ul> |
| 55 | + */ |
| 56 | + public ResponseObject<StyleGuide> getStyleGuide(Long styleGuideId) throws HttpException, HttpBadRequestException { |
| 57 | + StyleGuideResponseObject styleGuideResponseObject = this.httpClient.get(this.url + "/style-guides/" + styleGuideId, new HttpRequestConfig(), StyleGuideResponseObject.class); |
| 58 | + return ResponseObject.of(styleGuideResponseObject.getData()); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @param request request object |
| 63 | + * @return newly created style guide |
| 64 | + * @see <ul> |
| 65 | + * <li><a href="https://developer.crowdin.com/api/v2/#operation/api.style-guides.post" target="_blank"><b>API Documentation</b></a></li> |
| 66 | + * <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.style-guides.post" target="_blank"><b>Enterprise API Documentation</b></a></li> |
| 67 | + * </ul> |
| 68 | + */ |
| 69 | + public ResponseObject<StyleGuide> addStyleGuide(AddStyleGuideRequest request) throws HttpException, HttpBadRequestException { |
| 70 | + StyleGuideResponseObject styleGuideResponseObject = this.httpClient.post(this.url + "/style-guides", request, new HttpRequestConfig(), StyleGuideResponseObject.class); |
| 71 | + return ResponseObject.of(styleGuideResponseObject.getData()); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @param userId user identifier |
| 76 | + * @param limit maximum number of items to retrieve (default 25) |
| 77 | + * @param offset starting offset in the collection (default 0) |
| 78 | + * @return list of style guides |
| 79 | + * @see <ul> |
| 80 | + * <li><a href="https://developer.crowdin.com/api/v2/#operation/api.style-guides.getMany" target="_blank"><b>API Documentation</b></a></li> |
| 81 | + * <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.style-guides.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li> |
| 82 | + * </ul> |
| 83 | + */ |
| 84 | + public ResponseList<StyleGuide> listStyleGuides(Long userId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException { |
| 85 | + ListStyleGuidesParams params = new ListStyleGuidesParams(); |
| 86 | + params.setUserId(userId); |
| 87 | + params.setLimit(limit); |
| 88 | + params.setOffset(offset); |
| 89 | + return listStyleGuides(params); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * @param userId user identifier |
| 94 | + * @param limit maximum number of items to retrieve (default 25) |
| 95 | + * @param offset starting offset in the collection (default 0) |
| 96 | + * @param orderBy list of OrderByField |
| 97 | + * @return list of style guides |
| 98 | + * @see <ul> |
| 99 | + * <li><a href="https://developer.crowdin.com/api/v2/#operation/api.style-guides.getMany" target="_blank"><b>API Documentation</b></a></li> |
| 100 | + * <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.style-guides.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li> |
| 101 | + * </ul> |
| 102 | + */ |
| 103 | + public ResponseList<StyleGuide> listStyleGuides(Long userId, Integer limit, Integer offset, List<OrderByField> orderBy) throws HttpException, HttpBadRequestException { |
| 104 | + ListStyleGuidesParams params = new ListStyleGuidesParams(); |
| 105 | + params.setUserId(userId); |
| 106 | + params.setLimit(limit); |
| 107 | + params.setOffset(offset); |
| 108 | + params.setOrderByList(orderBy); |
| 109 | + return listStyleGuides(params); |
| 110 | + } |
| 111 | + |
| 112 | + public ResponseList<StyleGuide> listStyleGuides(ListStyleGuidesParams params) throws HttpException, HttpBadRequestException { |
| 113 | + ListStyleGuidesParams query = Optional.ofNullable(params).orElse(new ListStyleGuidesParams()); |
| 114 | + |
| 115 | + String orderBy = query.getOrderByList() != null |
| 116 | + ? OrderByField.generateSortParam(query.getOrderByList()) |
| 117 | + : query.getOrderBy(); |
| 118 | + |
| 119 | + Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams( |
| 120 | + "userId", Optional.ofNullable(query.getUserId()), |
| 121 | + "limit", Optional.ofNullable(query.getLimit()), |
| 122 | + "offset", Optional.ofNullable(query.getOffset()), |
| 123 | + "orderBy", Optional.ofNullable(orderBy) |
| 124 | + ); |
| 125 | + StyleGuideResponseList styleGuideResponseList = this.httpClient.get(this.url + "/style-guides", new HttpRequestConfig(queryParams), StyleGuideResponseList.class); |
| 126 | + return StyleGuideResponseList.to(styleGuideResponseList); |
| 127 | + } |
| 128 | +} |
0 commit comments