Skip to content

Commit

Permalink
add support to applications api closes #200
Browse files Browse the repository at this point in the history
  • Loading branch information
sugan0tech committed Oct 30, 2023
1 parent 94bca12 commit b80e2ce
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 0 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
@@ -1,5 +1,6 @@
package com.crowdin.client;

import com.crowdin.client.applications.ApplicationsApi;
import com.crowdin.client.bundles.BundlesApi;
import com.crowdin.client.core.CrowdinApi;
import com.crowdin.client.core.model.ClientConfig;
Expand Down Expand Up @@ -62,6 +63,7 @@ public class Client extends CrowdinApi {
private final StringCommentsApi stringCommentsApi;
private final BundlesApi bundlesApi;
private final NotificationsApi notificationsApi;
private final ApplicationsApi applicationsApi;

public Client(Credentials credentials) {
super(credentials);
Expand Down Expand Up @@ -92,6 +94,7 @@ public Client(Credentials credentials) {
this.stringCommentsApi = new StringCommentsApi(credentials);
this.bundlesApi = new BundlesApi(credentials);
this.notificationsApi = new NotificationsApi(credentials);
this.applicationsApi = new ApplicationsApi(credentials);
}

public Client(Credentials credentials, ClientConfig clientConfig) {
Expand Down Expand Up @@ -123,6 +126,7 @@ public Client(Credentials credentials, ClientConfig clientConfig) {
this.stringCommentsApi = new StringCommentsApi(credentials, clientConfig);
this.bundlesApi = new BundlesApi(credentials, clientConfig);
this.notificationsApi = new NotificationsApi(credentials, clientConfig);
this.applicationsApi = new ApplicationsApi(credentials, clientConfig);
}

}
97 changes: 97 additions & 0 deletions src/main/java/com/crowdin/client/applications/ApplicationsApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.crowdin.client.applications;

import com.crowdin.client.applications.model.*;
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.ResponseObject;


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

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

/**
* @param applicationIdentifier identifier of the application
* @param path The path is implemented by the application
* @return application data
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.applications.api.get" target="_blank"><b>API Documentation</b></a></li>
* <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 {
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());
}

/**
* @param applicationIdentifier identifier of the application
* @param path The path is implemented by the application
* @return application data
* @param request request object
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.applications.api.put" target="_blank"><b>API Documentation</b></a></li>
* <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> updateOrReplaceApplicationData(String applicationIdentifier, String path, UpdateOrRestoreApplicationDataRequest 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());
}

/**
* @param applicationIdentifier identifier of the application
* @param path The path is implemented by the application
* @param request request object
* @return application data
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.applications.api.post" target="_blank"><b>API Documentation</b></a></li>
* <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 {
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());
}

/**
* @param applicationIdentifier identifier of the application
* @param path The path is implemented by the application
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.members.delete" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.members.delete" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public void deleteApplicationData(String applicationIdentifier, String path) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/applications/%s/api/%s", this.url, applicationIdentifier, path);
this.httpClient.delete(builtUrl, new HttpRequestConfig(), Void.class);
}

/**
* @param applicationIdentifier identifier of the application
* @param path The path is implemented by the application
* @param request request object
* @return application data
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.applications.api.put" target="_blank"><b>API Documentation</b></a></li>
* <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 {
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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.crowdin.client.applications.model;

import lombok.Data;

import java.util.Map;

@Data
public class AddApplicationDataRequest {
private Map<String, Object> data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.crowdin.client.applications.model;

import lombok.Data;

import java.util.Map;

@Data
public class ApplicationData {
private Map<String, Object> data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.crowdin.client.applications.model;

import lombok.Data;

@Data
public class ApplicationDataResponseObject {
private ApplicationData data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.crowdin.client.applications.model;

import lombok.Data;

import java.util.Map;

@Data
public class EditApplicationDataRequest {
private Map<String, Object> data;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.crowdin.client.applications.model;

import lombok.Data;

import java.util.Map;

@Data
public class UpdateOrRestoreApplicationDataRequest {
private Map<String, Object> data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.crowdin.client.applications;

import com.crowdin.client.applications.model.*;
import com.crowdin.client.core.model.ResponseObject;
import com.crowdin.client.framework.RequestMock;
import com.crowdin.client.framework.TestClient;
import org.apache.http.client.methods.*;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

class ApplicationsApiTest extends TestClient {

private final String applicationIdentifier = "identifier";
private final String path = "path";
private final String builtUrl = this.url + "/applications/" + applicationIdentifier + "/api/" + path;

@Override
public List<RequestMock> getMocks() {
return Arrays.asList(
RequestMock.build(builtUrl, HttpGet.METHOD_NAME, "api/applications/applicationData.json"),
RequestMock.build(builtUrl, HttpPut.METHOD_NAME, "api/applications/updateOrRestoreApplicationData.json", "api/applications/applicationData.json"),
RequestMock.build(builtUrl, HttpPost.METHOD_NAME, "api/applications/addApplicationData.json", "api/applications/applicationData.json"),
RequestMock.build(builtUrl, HttpDelete.METHOD_NAME),
RequestMock.build(builtUrl, HttpPatch.METHOD_NAME, "api/applications/editApplicationData.json", "api/applications/applicationData.json")
);
}

@Test
void getApplicationData() {
ResponseObject<ApplicationData> response = this.getApplicationsApi().getApplicationData(applicationIdentifier, path);
assertNotNull(response);
}

@Test
void updateOrReplaceApplicationData() {
Map<String, Object> applicationDataPayload = new HashMap<>();
applicationDataPayload.put("updateKey", "value");
UpdateOrRestoreApplicationDataRequest updateOrRestoreApplicationDataRequest = new UpdateOrRestoreApplicationDataRequest();
updateOrRestoreApplicationDataRequest.setData(applicationDataPayload);
ResponseObject<ApplicationData> response = this.getApplicationsApi().updateOrReplaceApplicationData(applicationIdentifier, path, updateOrRestoreApplicationDataRequest);
assertNotNull(response);
}

@Test
void addApplicationData() {
Map<String, Object> addApplicationDataPayload = new HashMap<>();
addApplicationDataPayload.put("Key1", "value");
addApplicationDataPayload.put("Key2", "value");
AddApplicationDataRequest applicationDataRequest = new AddApplicationDataRequest();
applicationDataRequest.setData(addApplicationDataPayload);
ResponseObject<ApplicationData> response = this.getApplicationsApi().addApplicationData(applicationIdentifier, path, applicationDataRequest);
assertNotNull(response);
}

@Test
void deleteApplicationData() {
this.getApplicationsApi().deleteApplicationData(applicationIdentifier, path);
}

@Test
void editApplicationData() {
Map<String, Object> request = new HashMap<>();
request.put("editKey", "editedValue");
EditApplicationDataRequest editApplicationDataRequest = new EditApplicationDataRequest();
editApplicationDataRequest.setData(request);
ResponseObject<ApplicationData> response = this.getApplicationsApi().editApplicationData(applicationIdentifier, path, editApplicationDataRequest);
assertNotNull(response);
}

}
6 changes: 6 additions & 0 deletions src/test/resources/api/applications/addApplicationData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"data": {
"Key1":"value",
"Key2":"value"
}
}
6 changes: 6 additions & 0 deletions src/test/resources/api/applications/applicationData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"data": {
"customKey1": "value",
"customKey2": "value"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"data": {
"customKey1": "value",
"customKey2": "value"
}
}
5 changes: 5 additions & 0 deletions src/test/resources/api/applications/editApplicationData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"data": {
"editKey": "editedValue"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"data": {
"updateKey": "value"
}
}

0 comments on commit b80e2ce

Please sign in to comment.