Skip to content

Commit 9554ab1

Browse files
authored
Merge pull request #5 from roaldnefs/add-delete-mixin
Add DeleteMixin to delete resources
2 parents 49f6869 + 4cebb1d commit 9554ab1

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

docs/user/quickstart.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ object by its name::
8787
>>> print(f"{domain.name} was registered on {domain.registrationDate}")
8888
transipdemonstratie.nl was registered on 2011-04-29
8989

90+
We could also cancel a single :class:`Domain <transip.v6.objects.Domain>`
91+
object by its name::
92+
93+
>>> client.domains.delete('transipdemonstratie.nl')
94+
9095
VPSs
9196
----
9297

@@ -112,6 +117,11 @@ object by its name::
112117
>>> print(f"{vps.name} runs {vps.operatingSystem} and has IP address: '{vps.ipAddress}'")
113118
transipdemo-vps runs FreeBSD 10.0-RELEASE and has IP address: '141.138.136.129'
114119

120+
We could also cancel a single :class:`Vps <transip.v6.objects.Vps>`
121+
object by its name::
122+
123+
>>> client.vpss.delete('transipdemo-vps')
124+
115125
Errors and Exceptions
116126
---------------------
117127

transip/mixins.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ def get(self, id: str, **kwargs) -> Optional[Type[ApiObject]]:
4949
return None
5050

5151

52+
class DeleteMixin:
53+
"""Delete a single ApiObject."""
54+
55+
client: TransIP
56+
_path: str
57+
58+
def delete(self, id: str, **kwargs) -> None:
59+
if self._path:
60+
self.client.delete(f"{self._path}/{id}")
61+
62+
5263
class ListMixin:
5364
"""Retrieve a list of ApiObjects.
5465

transip/v6/services/domain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
from typing import Optional, Type
2121

2222
from transip.base import ApiService, ApiObject
23-
from transip.mixins import GetMixin, ListMixin
23+
from transip.mixins import GetMixin, DeleteMixin, ListMixin
2424
from transip.v6.objects.domain import Domain
2525

2626

27-
class DomainService(GetMixin, ListMixin, ApiService):
27+
class DomainService(GetMixin, DeleteMixin, ListMixin, ApiService):
2828

2929
_path: str = "/domains"
3030
_obj_cls: Optional[Type[ApiObject]] = Domain

transip/v6/services/vps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
from typing import Optional, Type
2121

2222
from transip.base import ApiService, ApiObject
23-
from transip.mixins import GetMixin, ListMixin
23+
from transip.mixins import GetMixin, DeleteMixin, ListMixin
2424
from transip.v6.objects.vps import Vps
2525

2626

27-
class VpsService(GetMixin, ListMixin, ApiService):
27+
class VpsService(GetMixin, DeleteMixin, ListMixin, ApiService):
2828

2929
_path: str = "/vps"
3030
_obj_cls: Optional[Type[ApiObject]] = Vps

0 commit comments

Comments
 (0)