-
Notifications
You must be signed in to change notification settings - Fork 136
added webhook api #934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
added webhook api #934
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ public class Client { | |
| private TasksHandler tasksHandler; | ||
| private KeysHandler keysHandler; | ||
| private JsonHandler jsonHandler; | ||
| private WebHooksHandler webHooksHandler; | ||
|
|
||
| /** | ||
| * Calls instance for Meilisearch client | ||
|
|
@@ -33,6 +34,7 @@ public Client(Config config) { | |
| this.tasksHandler = new TasksHandler(config); | ||
| this.keysHandler = new KeysHandler(config); | ||
| this.jsonHandler = config.jsonHandler; | ||
| this.webHooksHandler = new WebHooksHandler(config); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -544,6 +546,64 @@ public String generateTenantToken( | |
| return jwtToken; | ||
| } | ||
|
|
||
| /** | ||
| * Get a list of all webhooks configured in the current Meilisearch instance. | ||
| * | ||
| * @return List of all webhooks. | ||
| * @throws MeilisearchException if an error occurs. | ||
| */ | ||
| public Results<Webhook> getWebhooks() throws MeilisearchException { | ||
| return this.webHooksHandler.getWebhooks(); | ||
| } | ||
|
|
||
| /** | ||
| * Get a webhook specified by its unique Uuid. | ||
| * | ||
| * @return A single Webhook instance. | ||
| * @param webhookUuid Uuid v4 identifier of a webhook. | ||
| * @throws MeilisearchException if an error occurs. | ||
| */ | ||
| public Webhook getWebhook(UUID webhookUuid) throws MeilisearchException { | ||
| return this.webHooksHandler.getWebhook(webhookUuid); | ||
| } | ||
|
|
||
| /** | ||
| * Create a new webhook. When Meilisearch finishes processing a task, it sends the relevant task | ||
| * object to all configured webhooks | ||
| * | ||
| * @return A single Webhook instance. | ||
| * @param createUpdateWebhookRequest Request body containing headers and url for the new | ||
| * webhook. | ||
| * @throws MeilisearchException If an error occurs. | ||
| */ | ||
| public Webhook createWebhook(CreateUpdateWebhookRequest createUpdateWebhookRequest) | ||
| throws MeilisearchException { | ||
| return this.webHooksHandler.createWebhook(createUpdateWebhookRequest); | ||
| } | ||
|
|
||
| /** | ||
| * Update the configuration for the specified webhook. To remove a field, set its value to null. | ||
| * | ||
| * @param webhook_uuid Uuid v4 identifier of a webhook. | ||
| * @param createUpdateWebhookRequest Request body containing new header or url. | ||
| * @return A single webhook instance. | ||
| * @throws MeilisearchException If an error occurs. | ||
| */ | ||
| public Webhook updateWebhook( | ||
| UUID webhook_uuid, CreateUpdateWebhookRequest createUpdateWebhookRequest) | ||
| throws MeilisearchException { | ||
| return this.webHooksHandler.updateWebhook(webhook_uuid, createUpdateWebhookRequest); | ||
| } | ||
|
|
||
| /** | ||
| * Delete a webhook and stop sending task completion data to the target URL. | ||
| * | ||
| * @param webhook_uuid Uuid v4 identifier of a webhook. | ||
| */ | ||
| public void deleteWebhook(UUID webhook_uuid) throws MeilisearchException { | ||
| this.webHooksHandler.deleteWebhook(webhook_uuid); | ||
| } | ||
|
Comment on lines
+587
to
+605
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent parameter naming:
Proposed fix /**
* Update the configuration for the specified webhook. To remove a field, set its value to null.
*
- * `@param` webhook_uuid Uuid v4 identifier of a webhook.
+ * `@param` webhookUuid Uuid v4 identifier of a webhook.
* `@param` createUpdateWebhookRequest Request body containing new header or url.
* `@return` A single webhook instance.
* `@throws` MeilisearchException If an error occurs.
*/
public Webhook updateWebhook(
- UUID webhook_uuid, CreateUpdateWebhookRequest createUpdateWebhookRequest)
+ UUID webhookUuid, CreateUpdateWebhookRequest createUpdateWebhookRequest)
throws MeilisearchException {
- return this.webHooksHandler.updateWebhook(webhook_uuid, createUpdateWebhookRequest);
+ return this.webHooksHandler.updateWebhook(webhookUuid, createUpdateWebhookRequest);
}
/**
* Delete a webhook and stop sending task completion data to the target URL.
*
- * `@param` webhook_uuid Uuid v4 identifier of a webhook.
+ * `@param` webhookUuid Uuid v4 identifier of a webhook.
+ * `@throws` MeilisearchException If an error occurs.
*/
- public void deleteWebhook(UUID webhook_uuid) throws MeilisearchException {
- this.webHooksHandler.deleteWebhook(webhook_uuid);
+ public void deleteWebhook(UUID webhookUuid) throws MeilisearchException {
+ this.webHooksHandler.deleteWebhook(webhookUuid);
}🤖 Prompt for AI Agents |
||
|
|
||
| private Boolean isValidUUID(String apiKeyUid) { | ||
| try { | ||
| UUID uuid = UUID.fromString(apiKeyUid); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package com.meilisearch.sdk; | ||
|
|
||
| import com.meilisearch.sdk.exceptions.MeilisearchException; | ||
| import com.meilisearch.sdk.http.URLBuilder; | ||
| import com.meilisearch.sdk.model.CreateUpdateWebhookRequest; | ||
| import com.meilisearch.sdk.model.Results; | ||
| import com.meilisearch.sdk.model.Webhook; | ||
| import java.util.UUID; | ||
|
|
||
| public class WebHooksHandler { | ||
| private final HttpClient httpClient; | ||
|
|
||
| protected WebHooksHandler(Config config) { | ||
| this.httpClient = config.httpClient; | ||
| } | ||
|
|
||
| /** | ||
| * Gets a list of webhooks | ||
| * | ||
| * @return List of webhooks. | ||
| * @throws MeilisearchException if an error occurs | ||
| */ | ||
| Results<Webhook> getWebhooks() throws MeilisearchException { | ||
| return this.httpClient.get(webhooksPath().getURL(), Results.class, Webhook.class); | ||
| } | ||
|
|
||
| /** | ||
| * Gets a webhook from its uuid | ||
| * | ||
| * @param uuid Unique identifier of the webhook to get | ||
| * @return Meilisearch API response as Webhook instance | ||
| * @throws MeilisearchException if an error occurs | ||
| */ | ||
| Webhook getWebhook(UUID uuid) throws MeilisearchException { | ||
| return this.httpClient.get( | ||
| webhooksPath().addSubroute(uuid.toString()).getURL(), Webhook.class); | ||
| } | ||
|
|
||
| /** | ||
| * Create a new webhook | ||
| * | ||
| * @param createUpdateWebhookRequest Request body for creating a new webhook | ||
| * @return Meilisearch API response as Webhook instance | ||
| * @throws MeilisearchException if an error occurs | ||
| */ | ||
| Webhook createWebhook(CreateUpdateWebhookRequest createUpdateWebhookRequest) | ||
| throws MeilisearchException { | ||
| return this.httpClient.post( | ||
| webhooksPath().getURL(), createUpdateWebhookRequest, Webhook.class); | ||
| } | ||
|
|
||
| /** | ||
| * Update a webhook | ||
| * | ||
| * @param webhookUuid Unique identifier of a webhook to update | ||
| * @param createUpdateWebhookRequest Request body for updating a webhook | ||
| * @return Meilisearch API response as Webhook instance | ||
| * @throws MeilisearchException if an error occurs | ||
| */ | ||
| Webhook updateWebhook(UUID webhookUuid, CreateUpdateWebhookRequest createUpdateWebhookRequest) | ||
| throws MeilisearchException { | ||
| return this.httpClient.patch( | ||
| webhooksPath().addSubroute(webhookUuid.toString()).getURL(), | ||
| createUpdateWebhookRequest, | ||
| Webhook.class); | ||
| } | ||
|
|
||
| /** | ||
| * Delete a webhook | ||
| * | ||
| * @param webhookUuid Unique identifier of a webhook to update | ||
| * @throws MeilisearchException if an error occurs | ||
| */ | ||
| void deleteWebhook(UUID webhookUuid) throws MeilisearchException { | ||
| this.httpClient.delete( | ||
| webhooksPath().addSubroute(webhookUuid.toString()).getURL(), String.class); | ||
| } | ||
|
|
||
| private URLBuilder webhooksPath() { | ||
| return new URLBuilder("/webhooks"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.meilisearch.sdk.model; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.HashMap; | ||
| import lombok.NonNull; | ||
|
|
||
| /** | ||
| * Data structure used in request body while creating or updating a webhook. | ||
| * | ||
| * @see <a href="https://www.meilisearch.com/docs/reference/api/webhooks">API Specification</a> | ||
| */ | ||
| public class CreateUpdateWebhookRequest implements Serializable { | ||
| final String url; | ||
| final HashMap<String, Object> headers; | ||
|
|
||
| public CreateUpdateWebhookRequest( | ||
| @NonNull String url, @NonNull HashMap<String, Object> headers) { | ||
| this.url = url; | ||
| this.headers = headers; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.meilisearch.sdk.model; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.HashMap; | ||
| import java.util.UUID; | ||
| import lombok.Getter; | ||
|
|
||
| /** | ||
| * Webhook data structure. | ||
| * | ||
| * @see <a href="https://www.meilisearch.com/docs/reference/api/webhooks">API specification</a> | ||
| */ | ||
| public class Webhook implements Serializable { | ||
| @Getter protected final UUID uuid; | ||
| @Getter protected final String url; | ||
| @Getter protected final HashMap<String, String> headers; | ||
| @Getter protected final boolean isEditable; | ||
|
|
||
| public Webhook(UUID uuid, String url, HashMap<String, String> headers, boolean isEditable) { | ||
| this.uuid = uuid; | ||
| this.url = url; | ||
| this.headers = headers; | ||
| this.isEditable = isEditable; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.