Skip to content

Commit 63e7f94

Browse files
authored
Add .test() method to WebhookClient (#60)
1 parent 77fec4b commit 63e7f94

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
[0.3.0](../../releases/tag/v0.3.0) - 2021-08-31
5+
-----------------------------------------------
6+
7+
### Added
8+
9+
- added the `test()` method to the webhook client
10+
411
[0.2.0](../../releases/tag/v0.2.0) - 2021-08-09
512
-----------------------------------------------
613

docs/docs.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,7 @@ Sub-client for manipulating a single webhook.
21212121
* [get()](#webhookclient-get)
21222122
* [update()](#webhookclient-update)
21232123
* [delete()](#webhookclient-delete)
2124+
* [test()](#webhookclient-test)
21242125
* [dispatches()](#webhookclient-dispatches)
21252126

21262127
***
@@ -2191,6 +2192,24 @@ Delete the webhook.
21912192

21922193
***
21932194

2195+
#### [](#webhookclient-test) `WebhookClient.test()`
2196+
2197+
Test a webhook.
2198+
2199+
Creates a webhook dispatch with a dummy payload.
2200+
2201+
[https://docs.apify.com/api/v2#/reference/webhooks/webhook-test/test-webhook](https://docs.apify.com/api/v2#/reference/webhooks/webhook-test/test-webhook)
2202+
2203+
* **Returns**
2204+
2205+
The webhook dispatch created by the test
2206+
2207+
* **Return type**
2208+
2209+
`dict`, optional
2210+
2211+
***
2212+
21942213
#### [](#webhookclient-dispatches) `WebhookClient.dispatches()`
21952214

21962215
Get dispatches of the webhook.

src/apify_client/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.2.0'
1+
__version__ = '0.3.0'

src/apify_client/clients/resource_clients/webhook.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any, Dict, List, Optional
22

3-
from ..._utils import _snake_case_to_camel_case
3+
from ..._errors import ApifyApiError
4+
from ..._utils import _catch_not_found_or_throw, _parse_date_fields, _pluck_data, _snake_case_to_camel_case
45
from ...consts import WebhookEventType
56
from ..base import ResourceClient
67
from .webhook_dispatch_collection import WebhookDispatchCollectionClient
@@ -107,6 +108,30 @@ def delete(self) -> None:
107108
"""
108109
return self._delete()
109110

111+
def test(self) -> Optional[Dict]:
112+
"""Test a webhook.
113+
114+
Creates a webhook dispatch with a dummy payload.
115+
116+
https://docs.apify.com/api/v2#/reference/webhooks/webhook-test/test-webhook
117+
118+
Returns:
119+
dict, optional: The webhook dispatch created by the test
120+
"""
121+
try:
122+
response = self.http_client.call(
123+
url=self._url('test'),
124+
method='POST',
125+
params=self._params(),
126+
)
127+
128+
return _parse_date_fields(_pluck_data(response.json()))
129+
130+
except ApifyApiError as exc:
131+
_catch_not_found_or_throw(exc)
132+
133+
return None
134+
110135
def dispatches(self) -> WebhookDispatchCollectionClient:
111136
"""Get dispatches of the webhook.
112137

0 commit comments

Comments
 (0)