-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support to applications api closes #200
- Loading branch information
1 parent
94bca12
commit b80e2ce
Showing
13 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/main/java/com/crowdin/client/applications/ApplicationsApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/crowdin/client/applications/model/AddApplicationDataRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/crowdin/client/applications/model/ApplicationData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/crowdin/client/applications/model/ApplicationDataResponseObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/crowdin/client/applications/model/EditApplicationDataRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...ain/java/com/crowdin/client/applications/model/UpdateOrRestoreApplicationDataRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
76 changes: 76 additions & 0 deletions
76
src/test/java/com/crowdin/client/applications/ApplicationsApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"data": { | ||
"Key1":"value", | ||
"Key2":"value" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"data": { | ||
"customKey1": "value", | ||
"customKey2": "value" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/resources/api/applications/applicationDataRequest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"data": { | ||
"customKey1": "value", | ||
"customKey2": "value" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"data": { | ||
"editKey": "editedValue" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/resources/api/applications/updateOrRestoreApplicationData.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"data": { | ||
"updateKey": "value" | ||
} | ||
} |