Skip to content

Commit 05910d7

Browse files
howard-at-cb0xRAG
authored andcommitted
make delete a instance method (#75)
* make delete a instance method * Update test_webhook.py * Revert "Update test_webhook.py" This reverts commit becbc2e. * Revert "make delete a instance method" This reverts commit 7775cd2. * make delete() deprecated, introduce delete_webhook() * Update CHANGELOG.md * name instance method delete also * Revert "name instance method delete also" This reverts commit 505f8d6. * Update test_webhook.py * Update webhook.py * lint * Update webhook.py * modify comment and CHANGELOG
1 parent 4307127 commit 05910d7

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
### Added
66

7-
- `ExternalAddress` derived `Address` class.
7+
- Add `Webhook.delete_webhook` instance method to delete a webhook instance.
8+
- Add `ExternalAddress` derived `Address` class.
89

10+
### Deprecated
11+
12+
- Deprecate `Webhook.delete` static method in `Webhook` which deletes a webhook by its ID.
913

1014
## [0.13.0] - 2024-12-19
1115

@@ -14,7 +18,7 @@
1418
- Add support for fetching address reputation
1519
- Add `reputation` method to `Address` to fetch the reputation of the address.
1620
- Add support for registering, updating, and listing smart contracts that are
17-
deployed external to CDP.
21+
deployed external to CDP.
1822
- Add `network_id` to `WalletData` so that it is saved with the seed data and surfaced via the export function
1923
- Add ability to import external wallets into CDP via a BIP-39 mnemonic phrase, as a 1-of-1 wallet
2024
- Add ability to import WalletData files exported by the NodeJS CDP SDK
@@ -42,7 +46,7 @@ deployed external to CDP.
4246
### Added
4347

4448
- Add support for funding wallets (Alpha feature release)
45-
- Must reach out to CDP SDK Discord channel to be considered for this feature.
49+
- Must reach out to CDP SDK Discord channel to be considered for this feature.
4650
- Added create and update feature for `SmartContractEventActivity` webhook and its related event type filter.
4751

4852
### Fixed
@@ -88,7 +92,7 @@ deployed external to CDP.
8892
### Changed
8993

9094
- Make faucet transactions async i.e. using `faucet_tx.wait()` to wait for the transaction to be confirmed.
91-
- This will make the SDK more consistent and make faucet transactions more reliable.
95+
- This will make the SDK more consistent and make faucet transactions more reliable.
9296

9397
## [0.0.9] - 2024-10-29
9498

cdp/webhook.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import warnings
12
from collections.abc import Iterator
23

34
from cdp.cdp import Cdp
45
from cdp.client.models.create_webhook_request import CreateWebhookRequest
56
from cdp.client.models.update_webhook_request import UpdateWebhookRequest
67
from cdp.client.models.webhook import Webhook as WebhookModel
7-
from cdp.client.models.webhook import WebhookEventFilter, WebhookEventType, WebhookEventTypeFilter
8+
from cdp.client.models.webhook import (
9+
WebhookEventFilter,
10+
WebhookEventType,
11+
WebhookEventTypeFilter,
12+
)
813
from cdp.client.models.webhook_list import WebhookList
914

1015

@@ -143,9 +148,25 @@ def delete(webhook_id: str) -> None:
143148
Args:
144149
webhook_id (str): The ID of the webhook to delete.
145150
151+
Deprecated:
152+
This static method is deprecated. Please use the instance method instead:
153+
webhook_instance.delete_webhook()
154+
146155
"""
156+
warnings.warn(
157+
"This static method is deprecated. Please use the instance method instead: webhook_instance.delete_webhook()",
158+
DeprecationWarning,
159+
stacklevel=2,
160+
)
147161
Cdp.api_clients.webhooks.delete_webhook(webhook_id)
148162

163+
def delete_webhook(self) -> None:
164+
"""Delete this webhook.
165+
166+
This method deletes the current webhook instance from the system.
167+
"""
168+
Cdp.api_clients.webhooks.delete_webhook(self.id)
169+
149170
def update(
150171
self,
151172
notification_uri: str | None = None,

tests/test_webhook.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,16 @@ def test_webhook_update(mock_api_clients, webhook_factory):
9393
assert isinstance(updated_webhook, Webhook)
9494
assert updated_webhook.notification_uri == new_notification_uri
9595
assert updated_webhook.id == webhook.id
96+
97+
98+
@patch("cdp.Cdp.api_clients")
99+
def test_webhook_instance_delete(mock_api_clients, webhook_factory):
100+
"""Test Webhook instance delete method."""
101+
# Create a webhook instance using the factory
102+
webhook = Webhook(model=webhook_factory(webhook_id="webhook-123"))
103+
104+
# Call delete on the webhook instance
105+
webhook.delete_webhook()
106+
107+
# Verify the API client was called with the correct webhook ID
108+
mock_api_clients.webhooks.delete_webhook.assert_called_once_with("webhook-123")

0 commit comments

Comments
 (0)