|
| 1 | +package com.crowdin.client.distributions; |
| 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.PatchRequest; |
| 10 | +import com.crowdin.client.core.model.ResponseList; |
| 11 | +import com.crowdin.client.core.model.ResponseObject; |
| 12 | +import com.crowdin.client.distributions.model.AddDistributionRequest; |
| 13 | +import com.crowdin.client.distributions.model.Distribution; |
| 14 | +import com.crowdin.client.distributions.model.DistributionRelease; |
| 15 | +import com.crowdin.client.distributions.model.DistributionReleaseResponseObject; |
| 16 | +import com.crowdin.client.distributions.model.DistributionResponseList; |
| 17 | +import com.crowdin.client.distributions.model.DistributionResponseObject; |
| 18 | + |
| 19 | +import java.util.List; |
| 20 | +import java.util.Map; |
| 21 | +import java.util.Optional; |
| 22 | + |
| 23 | +public class DistributionsApi extends CrowdinApi { |
| 24 | + |
| 25 | + public DistributionsApi(Credentials credentials) { |
| 26 | + super(credentials); |
| 27 | + } |
| 28 | + |
| 29 | + public DistributionsApi(Credentials credentials, ClientConfig clientConfig) { |
| 30 | + super(credentials, clientConfig); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @param projectId project identifier |
| 35 | + * @param limit maximum number of items to retrieve (default 25) |
| 36 | + * @param offset starting offset in the collection (default 0) |
| 37 | + * @return list of distributions |
| 38 | + */ |
| 39 | + public ResponseList<Distribution> listDistributions(Long projectId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException { |
| 40 | + Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams( |
| 41 | + "limit", Optional.ofNullable(limit), |
| 42 | + "offset", Optional.ofNullable(offset) |
| 43 | + ); |
| 44 | + DistributionResponseList distributionResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/distributions", new HttpRequestConfig(queryParams), DistributionResponseList.class); |
| 45 | + return DistributionResponseList.to(distributionResponseList); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @param projectId project identifier |
| 50 | + * @param request request object |
| 51 | + * @return newly created distribution |
| 52 | + */ |
| 53 | + public ResponseObject<Distribution> addDistribution(Long projectId, AddDistributionRequest request) throws HttpException, HttpBadRequestException { |
| 54 | + DistributionResponseObject distributionResponseObject = this.httpClient.post(this.url + "/projects/" + projectId + "/distributions", request, new HttpRequestConfig(), DistributionResponseObject.class); |
| 55 | + return ResponseObject.of(distributionResponseObject.getData()); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @param projectId project identifier |
| 60 | + * @param hash hash |
| 61 | + * @return distribution |
| 62 | + */ |
| 63 | + public ResponseObject<Distribution> getDistribution(Long projectId, String hash) throws HttpException, HttpBadRequestException { |
| 64 | + DistributionResponseObject distributionResponseObject = this.httpClient.get(this.url + "/projects/" + projectId + "/distributions/" + hash, new HttpRequestConfig(), DistributionResponseObject.class); |
| 65 | + return ResponseObject.of(distributionResponseObject.getData()); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * @param projectId project identifier |
| 70 | + * @param hash hash |
| 71 | + */ |
| 72 | + public void deleteDistribution(Long projectId, String hash) throws HttpException, HttpBadRequestException { |
| 73 | + this.httpClient.delete(this.url + "/projects/" + projectId + "/distributions/" + hash, new HttpRequestConfig(), Void.class); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @param projectId project identifier |
| 78 | + * @param hash hash |
| 79 | + * @param request request object |
| 80 | + * @return updated distribution |
| 81 | + */ |
| 82 | + public ResponseObject<Distribution> editDistribution(Long projectId, String hash, List<PatchRequest> request) throws HttpException, HttpBadRequestException { |
| 83 | + DistributionResponseObject distributionResponseObject = this.httpClient.patch(this.url + "/projects/" + projectId + "/distributions/" + hash, request, new HttpRequestConfig(), DistributionResponseObject.class); |
| 84 | + return ResponseObject.of(distributionResponseObject.getData()); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * @param projectId project identifier |
| 89 | + * @param hash hash |
| 90 | + * @return distribution release |
| 91 | + */ |
| 92 | + public ResponseObject<DistributionRelease> getDistributionRelease(Long projectId, String hash) throws HttpException, HttpBadRequestException { |
| 93 | + DistributionReleaseResponseObject distributionReleaseResponseObject = this.httpClient.get(this.url + "/projects/" + projectId + "/distributions/" + hash + "/release", new HttpRequestConfig(), DistributionReleaseResponseObject.class); |
| 94 | + return ResponseObject.of(distributionReleaseResponseObject.getData()); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * @param projectId project identifier |
| 99 | + * @param hash hash |
| 100 | + * @return distribution release |
| 101 | + */ |
| 102 | + public ResponseObject<DistributionRelease> createDistributionRelease(Long projectId, String hash) throws HttpException, HttpBadRequestException { |
| 103 | + DistributionReleaseResponseObject distributionReleaseResponseObject = this.httpClient.post(this.url + "/projects/" + projectId + "/distributions/" + hash + "/release", null, new HttpRequestConfig(), DistributionReleaseResponseObject.class); |
| 104 | + return ResponseObject.of(distributionReleaseResponseObject.getData()); |
| 105 | + } |
| 106 | +} |
0 commit comments