-
Notifications
You must be signed in to change notification settings - Fork 141
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
Merged
Merged
added webhook api #934
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9317713
added webhook api
valkrypton d43bd59
Lint
Strift 53a24af
Remove extra empty lines
Strift 7a3413e
Merge branch 'main' into add/webhooks-api
Strift 2f45138
fixed ci error
valkrypton 21fee6e
Update webhookUuid variable casing
Strift File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,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"); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/meilisearch/sdk/model/CreateUpdateWebhookRequest.java
This file contains hidden or 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,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; | ||
| } | ||
| } |
This file contains hidden or 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,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; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.