|
32 | 32 | from meilisearch.index import Index |
33 | 33 | from meilisearch.models.key import Key, KeysResults |
34 | 34 | from meilisearch.models.task import Batch, BatchResults, Task, TaskInfo, TaskResults |
| 35 | +from meilisearch.models.webhook import Webhook, WebhooksResults |
35 | 36 | from meilisearch.task import TaskHandler |
36 | 37 |
|
37 | 38 |
|
@@ -465,6 +466,119 @@ def delete_key(self, key_or_uid: str) -> int: |
465 | 466 |
|
466 | 467 | return response.status_code |
467 | 468 |
|
| 469 | + # WEBHOOKS ROUTES |
| 470 | + |
| 471 | + def get_webhooks(self) -> WebhooksResults: |
| 472 | + """Get all webhooks. |
| 473 | +
|
| 474 | + Returns |
| 475 | + ------- |
| 476 | + webhooks: |
| 477 | + WebhooksResults instance containing list of webhooks and pagination info. |
| 478 | + https://www.meilisearch.com/docs/reference/api/webhooks |
| 479 | +
|
| 480 | + Raises |
| 481 | + ------ |
| 482 | + MeilisearchApiError |
| 483 | + An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors |
| 484 | + """ |
| 485 | + webhooks = self.http.get(f"{self.config.paths.webhooks}") |
| 486 | + return WebhooksResults(**webhooks) |
| 487 | + |
| 488 | + def get_webhook(self, webhook_uuid: str) -> Webhook: |
| 489 | + """Get information about a specific webhook. |
| 490 | +
|
| 491 | + Parameters |
| 492 | + ---------- |
| 493 | + webhook_uuid: |
| 494 | + The uuid of the webhook to retrieve. |
| 495 | +
|
| 496 | + Returns |
| 497 | + ------- |
| 498 | + webhook: |
| 499 | + The webhook information. |
| 500 | + https://www.meilisearch.com/docs/reference/api/webhooks#get-one-webhook |
| 501 | +
|
| 502 | + Raises |
| 503 | + ------ |
| 504 | + MeilisearchApiError |
| 505 | + An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors |
| 506 | + """ |
| 507 | + webhook = self.http.get(f"{self.config.paths.webhooks}/{webhook_uuid}") |
| 508 | + return Webhook(**webhook) |
| 509 | + |
| 510 | + def create_webhook(self, options: Mapping[str, Any]) -> Webhook: |
| 511 | + """Create a new webhook. |
| 512 | +
|
| 513 | + Parameters |
| 514 | + ---------- |
| 515 | + options: |
| 516 | + The webhook configuration. Can include: |
| 517 | + - url: The URL to send the webhook to |
| 518 | + - headers: Dictionary of HTTP headers to include in webhook requests |
| 519 | +
|
| 520 | + Returns |
| 521 | + ------- |
| 522 | + webhook: |
| 523 | + The newly created webhook. |
| 524 | + https://www.meilisearch.com/docs/reference/api/webhooks#create-a-webhook |
| 525 | +
|
| 526 | + Raises |
| 527 | + ------ |
| 528 | + MeilisearchApiError |
| 529 | + An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors |
| 530 | + """ |
| 531 | + webhook = self.http.post(self.config.paths.webhooks, options) |
| 532 | + return Webhook(**webhook) |
| 533 | + |
| 534 | + def update_webhook(self, webhook_uuid: str, options: Mapping[str, Any]) -> Webhook: |
| 535 | + """Update an existing webhook. |
| 536 | +
|
| 537 | + Parameters |
| 538 | + ---------- |
| 539 | + webhook_uuid: |
| 540 | + The uuid of the webhook to update. |
| 541 | + options: |
| 542 | + The webhook fields to update. Can include: |
| 543 | + - url: The URL to send the webhook to |
| 544 | + - headers: Dictionary of HTTP headers to include in webhook requests |
| 545 | +
|
| 546 | + Returns |
| 547 | + ------- |
| 548 | + webhook: |
| 549 | + The updated webhook. |
| 550 | + https://www.meilisearch.com/docs/reference/api/webhooks#update-a-webhook |
| 551 | +
|
| 552 | + Raises |
| 553 | + ------ |
| 554 | + MeilisearchApiError |
| 555 | + An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors |
| 556 | + """ |
| 557 | + webhook = self.http.patch(f"{self.config.paths.webhooks}/{webhook_uuid}", options) |
| 558 | + return Webhook(**webhook) |
| 559 | + |
| 560 | + def delete_webhook(self, webhook_uuid: str) -> int: |
| 561 | + """Delete a webhook. |
| 562 | +
|
| 563 | + Parameters |
| 564 | + ---------- |
| 565 | + webhook_uuid: |
| 566 | + The uuid of the webhook to delete. |
| 567 | +
|
| 568 | + Returns |
| 569 | + ------- |
| 570 | + status_code: |
| 571 | + The Response status code. 204 signifies a successful delete. |
| 572 | + https://www.meilisearch.com/docs/reference/api/webhooks#delete-a-webhook |
| 573 | +
|
| 574 | + Raises |
| 575 | + ------ |
| 576 | + MeilisearchApiError |
| 577 | + An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors |
| 578 | + """ |
| 579 | + response = self.http.delete(f"{self.config.paths.webhooks}/{webhook_uuid}") |
| 580 | + return response.status_code |
| 581 | + |
468 | 582 | def get_version(self) -> Dict[str, str]: |
469 | 583 | """Get version Meilisearch |
470 | 584 |
|
|
0 commit comments