|
| 1 | +package com.crowdin.client.stringcorrections; |
| 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.ClientConfig; |
| 8 | +import com.crowdin.client.core.model.Credentials; |
| 9 | +import com.crowdin.client.core.model.ResponseList; |
| 10 | +import com.crowdin.client.core.model.ResponseObject; |
| 11 | +import com.crowdin.client.stringcorrections.model.*; |
| 12 | + |
| 13 | +import java.util.Map; |
| 14 | +import java.util.Optional; |
| 15 | + |
| 16 | +public class StringCorrectionsApi extends CrowdinApi { |
| 17 | + |
| 18 | + |
| 19 | + public StringCorrectionsApi(Credentials credentials) { |
| 20 | + super(credentials); |
| 21 | + } |
| 22 | + |
| 23 | + public StringCorrectionsApi(Credentials credentials, ClientConfig clientConfig) { |
| 24 | + super(credentials, clientConfig); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * @param projectId project identifier |
| 29 | + * @param params query params |
| 30 | + * @return list of corrections |
| 31 | + * @see <ul> |
| 32 | + * <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li> |
| 33 | + * </ul> |
| 34 | + */ |
| 35 | + public ResponseList<Correction> listCorrections(Long projectId, ListCorrectionsQueryParams params) throws HttpException, HttpBadRequestException { |
| 36 | + Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams( |
| 37 | + "stringId", Optional.of(params.getStringId()), |
| 38 | + "orderBy", Optional.ofNullable(params.getOrderBy()), |
| 39 | + "denormalizePlaceholders", Optional.ofNullable(params.getDenormalizePlaceholders()), |
| 40 | + "limit", Optional.ofNullable(params.getLimit()), |
| 41 | + "offset", Optional.ofNullable(params.getOffset()) |
| 42 | + ); |
| 43 | + CorrectionResponseList response = this.httpClient.get(this.url + "/projects/" + projectId + "/corrections", new HttpRequestConfig(queryParams), CorrectionResponseList.class); |
| 44 | + return CorrectionResponseList.to(response); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @param projectId project identifier |
| 49 | + * @param request request object |
| 50 | + * @return newly created correction |
| 51 | + * @see <ul> |
| 52 | + * <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.post" target="_blank"><b>Enterprise API Documentation</b></a></li> |
| 53 | + * </ul> |
| 54 | + */ |
| 55 | + public ResponseObject<Correction> addCorrection(Long projectId, AddCorrectionRequest request) throws HttpException, HttpBadRequestException { |
| 56 | + CorrectionResponseObject response = this.httpClient.post(this.url + "/projects/" + projectId + "/corrections", request, new HttpRequestConfig(), CorrectionResponseObject.class); |
| 57 | + return ResponseObject.of(response.getData()); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @param projectId project identifier |
| 62 | + * @param correctionId correction identifier |
| 63 | + * @return correction object |
| 64 | + * @see <ul> |
| 65 | + * <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.get" target="_blank"><b>Enterprise API Documentation</b></a></li> |
| 66 | + * </ul> |
| 67 | + */ |
| 68 | + public ResponseObject<Correction> getCorrection(Long projectId, Long correctionId) throws HttpException, HttpBadRequestException { |
| 69 | + CorrectionResponseObject response = this.httpClient.get(this.url + "/projects/" + projectId + "/corrections/" + correctionId, new HttpRequestConfig(), CorrectionResponseObject.class); |
| 70 | + return ResponseObject.of(response.getData()); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @param projectId project identifier |
| 75 | + * @param stringId string identifier |
| 76 | + * @see <ul> |
| 77 | + * <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.deleteMany" target="_blank"><b>Enterprise API Documentation</b></a></li> |
| 78 | + * </ul> |
| 79 | + */ |
| 80 | + public void deleteCorrections(Long projectId, Long stringId) throws HttpException, HttpBadRequestException { |
| 81 | + Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams( |
| 82 | + "stringId", Optional.of(stringId) |
| 83 | + ); |
| 84 | + this.httpClient.delete(this.url + "/projects/" + projectId + "/corrections", new HttpRequestConfig(queryParams), Void.class); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * @param projectId project identifier |
| 89 | + * @param correctionId correction identifier |
| 90 | + * @return newly created correction |
| 91 | + * @see <ul> |
| 92 | + * <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.put" target="_blank"><b>Enterprise API Documentation</b></a></li> |
| 93 | + * </ul> |
| 94 | + */ |
| 95 | + public ResponseObject<Correction> restoreCorrection(Long projectId, Long correctionId) throws HttpException, HttpBadRequestException { |
| 96 | + CorrectionResponseObject response = this.httpClient.put(this.url + "/projects/" + projectId + "/corrections/" + correctionId, null, new HttpRequestConfig(), CorrectionResponseObject.class); |
| 97 | + return ResponseObject.of(response.getData()); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @param projectId project identifier |
| 102 | + * @param correctionId correction identifier |
| 103 | + * @see <ul> |
| 104 | + * <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.delete" target="_blank"><b>Enterprise API Documentation</b></a></li> |
| 105 | + * </ul> |
| 106 | + */ |
| 107 | + public void deleteCorrection(Long projectId, Long correctionId) throws HttpException, HttpBadRequestException { |
| 108 | + this.httpClient.delete(this.url + "/projects/" + projectId + "/corrections/" + correctionId, new HttpRequestConfig(), Void.class); |
| 109 | + } |
| 110 | + |
| 111 | +} |
0 commit comments