-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(api): Organization Webhooks: refactoring before merge
- Loading branch information
Showing
5 changed files
with
119 additions
and
95 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
107 changes: 107 additions & 0 deletions
107
src/main/java/com/crowdin/client/webhooks/OrganizationWebhooksApi.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,107 @@ | ||
package com.crowdin.client.webhooks; | ||
|
||
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.PatchRequest; | ||
import com.crowdin.client.core.model.ResponseList; | ||
import com.crowdin.client.core.model.ResponseObject; | ||
import com.crowdin.client.webhooks.model.AddOrganizationWebhookRequest; | ||
import com.crowdin.client.webhooks.model.OrgWebhookResponseList; | ||
import com.crowdin.client.webhooks.model.OrgWebhookResponseObject; | ||
import com.crowdin.client.webhooks.model.OrganizationWebhook; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class OrganizationWebhooksApi extends CrowdinApi { | ||
public OrganizationWebhooksApi(Credentials credentials) { | ||
super(credentials); | ||
} | ||
|
||
public OrganizationWebhooksApi(Credentials credentials, ClientConfig clientConfig) { | ||
super(credentials, clientConfig); | ||
} | ||
|
||
private final String baseUrl = "/webhooks"; | ||
|
||
/** | ||
* @param limit maximum number of items to retrieve (default 25) | ||
* @param offset starting offset in the collection (default 0) | ||
* @return list of organization webhooks | ||
* @see <ul> | ||
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.webhooks.getMany" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.webhooks.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
* </ul> | ||
*/ | ||
public ResponseList<OrganizationWebhook> listWebhooks(Integer limit, Integer offset) throws HttpException, HttpBadRequestException { | ||
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams( | ||
"limit", Optional.ofNullable(limit), | ||
"offset", Optional.ofNullable(offset) | ||
); | ||
OrgWebhookResponseList responseList = this.httpClient.get(baseUrl, new HttpRequestConfig(queryParams), OrgWebhookResponseList.class); | ||
return OrgWebhookResponseList.to(responseList); | ||
} | ||
|
||
/** | ||
* @param request request object | ||
* @return newly created organization webhook | ||
* @see <ul> | ||
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.webhooks.post" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.webhooks.post" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
* </ul> | ||
*/ | ||
public ResponseObject<OrganizationWebhook> addWebhook(AddOrganizationWebhookRequest request) throws HttpException, HttpBadRequestException { | ||
OrgWebhookResponseObject responseObject = this.httpClient.post(baseUrl, request, new HttpRequestConfig(), OrgWebhookResponseObject.class); | ||
return ResponseObject.of(responseObject.getData()); | ||
} | ||
|
||
/** | ||
* @param organizationWebhookId organization webhook identifier | ||
* @return organization webhook | ||
* @see <ul> | ||
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.webhooks.get" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.webhooks.get" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
* </ul> | ||
*/ | ||
public ResponseObject<OrganizationWebhook> getWebhook(Long organizationWebhookId) throws HttpException, HttpBadRequestException { | ||
String url = formUrl_webhookId(organizationWebhookId); | ||
OrgWebhookResponseObject responseObject = this.httpClient.get(url, new HttpRequestConfig(), OrgWebhookResponseObject.class); | ||
return ResponseObject.of(responseObject.getData()); | ||
} | ||
|
||
/** | ||
* @param organizationWebhookId organization webhook identifier | ||
* @see <ul> | ||
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.webhooks.delete" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.webhooks.delete" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
* </ul> | ||
*/ | ||
public void deleteWebhook(Long organizationWebhookId) throws HttpException, HttpBadRequestException { | ||
String url = formUrl_webhookId(organizationWebhookId); | ||
this.httpClient.delete(url, new HttpRequestConfig(), Void.class); | ||
} | ||
|
||
/** | ||
* @param organizationWebhookId organization webhook identifier | ||
* @param request request object | ||
* @return updated organization webhook | ||
* @see <ul> | ||
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.webhooks.patch" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.webhooks.patch" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
* </ul> | ||
*/ | ||
public ResponseObject<OrganizationWebhook> editWebhook(Long organizationWebhookId, List<PatchRequest> request) throws HttpException, HttpBadRequestException { | ||
String url = formUrl_webhookId(organizationWebhookId); | ||
OrgWebhookResponseObject responseObject = this.httpClient.patch(url, request, new HttpRequestConfig(), OrgWebhookResponseObject.class); | ||
return ResponseObject.of(responseObject.getData()); | ||
} | ||
|
||
private String formUrl_webhookId(Long organizationWebhookId) { | ||
return this.url + "/webhooks/" + organizationWebhookId; | ||
} | ||
} |
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
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
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