Skip to content

Commit

Permalink
Merge pull request #212 from crowdin/strings-based-api
Browse files Browse the repository at this point in the history
feat: Strings-based API
  • Loading branch information
yevheniyJ authored Nov 24, 2023
2 parents bf013a7 + e0434c6 commit 7f93513
Show file tree
Hide file tree
Showing 128 changed files with 1,540 additions and 371 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/crowdin/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.crowdin.client.applications.ApplicationsApi;
import com.crowdin.client.bundles.BundlesApi;
import com.crowdin.client.clients.ClientsApi;
import com.crowdin.client.core.CrowdinApi;
import com.crowdin.client.core.model.ClientConfig;
import com.crowdin.client.core.model.Credentials;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class Client extends CrowdinApi {
private final BundlesApi bundlesApi;
private final NotificationsApi notificationsApi;
private final ApplicationsApi applicationsApi;
private final ClientsApi clientsApi;

public Client(Credentials credentials) {
super(credentials);
Expand Down Expand Up @@ -95,6 +97,7 @@ public Client(Credentials credentials) {
this.bundlesApi = new BundlesApi(credentials);
this.notificationsApi = new NotificationsApi(credentials);
this.applicationsApi = new ApplicationsApi(credentials);
this.clientsApi = new ClientsApi(credentials);
}

public Client(Credentials credentials, ClientConfig clientConfig) {
Expand Down Expand Up @@ -127,6 +130,7 @@ public Client(Credentials credentials, ClientConfig clientConfig) {
this.bundlesApi = new BundlesApi(credentials, clientConfig);
this.notificationsApi = new NotificationsApi(credentials, clientConfig);
this.applicationsApi = new ApplicationsApi(credentials, clientConfig);
this.clientsApi = new ClientsApi(credentials, clientConfig);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.crowdin.client.core.model.Credentials;
import com.crowdin.client.core.model.ResponseObject;

import java.util.Map;


public class ApplicationsApi extends CrowdinApi {
public ApplicationsApi(Credentials credentials) {
Expand All @@ -28,7 +30,7 @@ public ApplicationsApi(Credentials credentials, ClientConfig clientConfig) {
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.api.get" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<ApplicationData> getApplicationData(String applicationIdentifier, String path) throws HttpException, HttpBadRequestException {
public ResponseObject<Map<String, Object>> getApplicationData(String applicationIdentifier, String path) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/applications/%s/api/%s", this.url, applicationIdentifier, path);
ApplicationDataResponseObject response = this.httpClient.get(builtUrl, new HttpRequestConfig(), ApplicationDataResponseObject.class);
return ResponseObject.of(response.getData());
Expand All @@ -44,7 +46,7 @@ public ResponseObject<ApplicationData> getApplicationData(String applicationIden
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.api.put" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<ApplicationData> updateOrRestoreApplicationData(String applicationIdentifier, String path, UpdateOrRestoreApplicationDataRequest request) throws HttpException, HttpBadRequestException {
public ResponseObject<Map<String, Object>> updateOrRestoreApplicationData(String applicationIdentifier, String path, Map<String, Object> request) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/applications/%s/api/%s", this.url, applicationIdentifier, path);
ApplicationDataResponseObject response = this.httpClient.put(builtUrl, request, new HttpRequestConfig(), ApplicationDataResponseObject.class);
return ResponseObject.of(response.getData());
Expand All @@ -60,7 +62,7 @@ public ResponseObject<ApplicationData> updateOrRestoreApplicationData(String app
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.api.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<ApplicationData> addApplicationData(String applicationIdentifier, String path, AddApplicationDataRequest request) throws HttpException, HttpBadRequestException {
public ResponseObject<Map<String, Object>> addApplicationData(String applicationIdentifier, String path, Map<String, Object> request) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/applications/%s/api/%s", this.url, applicationIdentifier, path);
ApplicationDataResponseObject response = this.httpClient.post(builtUrl, request, new HttpRequestConfig(), ApplicationDataResponseObject.class);
return ResponseObject.of(response.getData());
Expand Down Expand Up @@ -89,7 +91,7 @@ public void deleteApplicationData(String applicationIdentifier, String path) thr
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.api.put" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<ApplicationData> editApplicationData(String applicationIdentifier, String path, EditApplicationDataRequest request) throws HttpException, HttpBadRequestException {
public ResponseObject<Map<String, Object>> editApplicationData(String applicationIdentifier, String path, Map<String, Object> request) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/applications/%s/api/%s", this.url, applicationIdentifier, path);
ApplicationDataResponseObject response = this.httpClient.patch(builtUrl, request, new HttpRequestConfig(), ApplicationDataResponseObject.class);
return ResponseObject.of(response.getData());
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import lombok.Data;

import java.util.Map;

@Data
public class ApplicationDataResponseObject {
private ApplicationData data;
private Map<String, Object> data;
}

This file was deleted.

This file was deleted.

58 changes: 43 additions & 15 deletions src/main/java/com/crowdin/client/bundles/BundlesApi.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package com.crowdin.client.bundles;

import com.crowdin.client.bundles.model.*;
import com.crowdin.client.bundles.model.AddBundleRequest;
import com.crowdin.client.bundles.model.Bundle;
import com.crowdin.client.bundles.model.BundleExport;
import com.crowdin.client.bundles.model.BundleExportResponseObject;
import com.crowdin.client.bundles.model.BundleResponseList;
import com.crowdin.client.bundles.model.BundleResponseObject;
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.core.model.ClientConfig;
import com.crowdin.client.core.model.Credentials;
import com.crowdin.client.core.model.DownloadLink;
import com.crowdin.client.core.model.DownloadLinkResponseObject;
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.sourcefiles.model.Branch;
import com.crowdin.client.sourcefiles.model.BranchResponseList;
import com.crowdin.client.sourcefiles.model.FileInfo;
import com.crowdin.client.sourcefiles.model.FileInfoResponseList;

Expand Down Expand Up @@ -39,7 +52,7 @@ public ResponseList<Bundle> listBundles(Long projectId) throws HttpException, Ht

/**
* @param projectId project identifier
* @param request request object
* @param request request object
* @return newly created bundle
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.post" target="_blank"><b>API Documentation</b></a></li>
Expand All @@ -53,7 +66,7 @@ public ResponseObject<Bundle> addBundle(Long projectId, AddBundleRequest request

/**
* @param projectId project identifier
* @param bundleId bundle identifier
* @param bundleId bundle identifier
* @return bundle object
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.get" target="_blank"><b>API Documentation</b></a></li>
Expand All @@ -67,7 +80,7 @@ public ResponseObject<Bundle> getBundle(Long projectId, Long bundleId) throws Ht

/**
* @param projectId project identifier
* @param bundleId bundle identifier
* @param bundleId bundle identifier
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.delete" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.delete" target="_blank"><b>Enterprise API Documentation</b></a></li>
Expand All @@ -79,8 +92,8 @@ public void deleteBundle(Long projectId, Long bundleId) throws HttpException, Ht

/**
* @param projectId project identifier
* @param bundleId bundle identifier
* @param request request object
* @param bundleId bundle identifier
* @param request request object
* @return updated bundle
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.patch" target="_blank"><b>API Documentation</b></a></li>
Expand All @@ -94,9 +107,9 @@ public ResponseObject<Bundle> editBundle(Long projectId, Long bundleId, List<Pat

/**
* @param projectId project identifier
* @param bundleId bundle identifier
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
* @param bundleId bundle identifier
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
* @return list of bundles file resource
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.files.getMany" target="_blank"><b>API Documentation</b></a></li>
Expand All @@ -114,8 +127,23 @@ public ResponseList<? extends FileInfo> listBundleFiles(Long projectId, Long bun

/**
* @param projectId project identifier
* @param bundleId bundle identifier
* @param exportId export identifier, consists of 36 characters
* @param bundleId bundle identifier
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
*/
public ResponseList<Branch> listBundleBranches(Long projectId, Long bundleId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);
BranchResponseList response = this.httpClient.get(this.url + "/projects/" + projectId + "/bundles/" + bundleId + "/branches", new HttpRequestConfig(queryParams), BranchResponseList.class);
return BranchResponseList.to(response);
}

/**
* @param projectId project identifier
* @param bundleId bundle identifier
* @param exportId export identifier, consists of 36 characters
* @return download link to bundle
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.download.get" target="_blank"><b>API Documentation</b></a></li>
Expand All @@ -132,7 +160,7 @@ public ResponseObject<DownloadLink> downloadBundle(Long projectId, Long bundleId

/**
* @param projectId project identifier
* @param bundleId bundle identifier
* @param bundleId bundle identifier
* @return freshly created bundle export object
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.post" target="_blank"><b>API Documentation</b></a></li>
Expand All @@ -149,8 +177,8 @@ public ResponseObject<BundleExport> exportBundle(Long projectId, Long bundleId)

/**
* @param projectId project identifier
* @param bundleId bundle identifier
* @param exportId export identifier, consists of 36 characters
* @param bundleId bundle identifier
* @param exportId export identifier, consists of 36 characters
* @return requested bundle export object
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.get" target="_blank"><b>API Documentation</b></a></li>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/crowdin/client/bundles/model/Bundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Bundle {
private boolean isMultilingual;
private Boolean includeProjectSourceLanguage;
private List<Long> labelIds;
private List<Long> excludeLabelIds;
private Date createdAt;
private Date updatedAt;
}
41 changes: 41 additions & 0 deletions src/main/java/com/crowdin/client/clients/ClientsApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.crowdin.client.clients;

import com.crowdin.client.clients.model.Client;
import com.crowdin.client.clients.model.ClientResponseList;
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.ClientConfig;
import com.crowdin.client.core.model.Credentials;
import com.crowdin.client.core.model.ResponseList;

import java.util.Map;
import java.util.Optional;

public class ClientsApi extends CrowdinApi {
public ClientsApi(Credentials credentials) {
super(credentials);
}

public ClientsApi(Credentials credentials, ClientConfig clientConfig) {
super(credentials, clientConfig);
}

/**
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
* @return list of vendors
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.clients.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<Client> listClients(Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Map<String, Optional<Integer>> queryParams = HttpRequestConfig.buildUrlParams(
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);
ClientResponseList vendorResponseList = this.httpClient.get(this.url + "/clients", new HttpRequestConfig(queryParams), ClientResponseList.class);
return ClientResponseList.to(vendorResponseList);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/crowdin/client/clients/model/Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.crowdin.client.clients.model;

import lombok.Data;

@Data
public class Client {

private Long id;
private String name;
private String description;
private Status status;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.crowdin.client.clients.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 ClientResponseList {

private List<ClientResponseObject> data;
private Pagination pagination;

public static ResponseList<Client> to(ClientResponseList vendorResponseList) {
return ResponseList.of(
vendorResponseList.getData().stream()
.map(ClientResponseObject::getData)
.map(ResponseObject::of)
.collect(Collectors.toList()),
vendorResponseList.getPagination()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.crowdin.client.clients.model;

import lombok.Data;

@Data
public class ClientResponseObject {

private Client data;
}
17 changes: 17 additions & 0 deletions src/main/java/com/crowdin/client/clients/model/Status.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.crowdin.client.clients.model;

import com.crowdin.client.core.model.EnumConverter;

public enum Status implements EnumConverter<Status> {

PENDING, CONFIRMED, REJECTED;

public static Status from(String value) {
return Status.valueOf(value.toUpperCase());
}

@Override
public String to(Status v) {
return v.name().toLowerCase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public FileFormatSettingsResource deserialize(JsonParser parser, Deserialization
case "mdxV1":
classToUse = MdxV1FileFormatSettings.class;
break;
case "mdxV2":
classToUse = MdxV2FileFormatSettings.class;
break;
case "fmMd":
classToUse = FmMdFileFormatSettings.class;
break;
Expand Down Expand Up @@ -81,6 +84,9 @@ public FileFormatSettingsResource deserialize(JsonParser parser, Deserialization
case "json":
classToUse = JsonFileFormatSettings.class;
break;
case "js":
classToUse = JavaScriptFileFormatSettings.class;
break;
case "fjs":
classToUse = FJSFileFormatSettings.class;
break;
Expand Down
Loading

0 comments on commit 7f93513

Please sign in to comment.