Skip to content

Commit c3e6f24

Browse files
committed
add Paste.delete
1 parent fca00b4 commit c3e6f24

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

mystbin/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async def create_paste(
8484
The paste that was created.
8585
"""
8686
data = await self.http.create_paste(files=files, password=password, expires=expires)
87-
return Paste.from_create(data, files=files)
87+
return Paste.from_create(data, files=files, http=self.http)
8888

8989
async def delete_paste(self, security_token: str, /) -> None:
9090
"""|coro|
@@ -130,4 +130,4 @@ async def get_paste(self, paste_id: str, *, password: str | None = None, raw: bo
130130
data = await self.http.get_paste(paste_id=paste_id, password=password)
131131
if raw:
132132
return [item["content"] for item in data["files"]]
133-
return Paste.from_get(data)
133+
return Paste.from_get(data, http=self.http)

mystbin/paste.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030

3131
from typing_extensions import Self
3232

33-
from mystbin.types.responses import CreatePasteResponse, FileResponse, GetPasteResponse
33+
from .http import HTTPClient
34+
from .types.responses import CreatePasteResponse, FileResponse, GetPasteResponse
3435

3536

3637
__all__ = (
@@ -126,9 +127,11 @@ class Paste:
126127
"_security",
127128
"_expires",
128129
"_views",
130+
"_http",
129131
)
130132

131-
def __init__(self, *, id: str, created_at: str, files: Sequence[File]) -> None:
133+
def __init__(self, *, http: HTTPClient, id: str, created_at: str, files: Sequence[File]) -> None:
134+
self._http: HTTPClient = http
132135
self.id: str = id
133136
self.created_at: datetime.datetime = datetime.datetime.fromisoformat(created_at)
134137
self.files: Sequence[File] = files
@@ -156,9 +159,10 @@ def security_token(self) -> str | None:
156159
return self._security
157160

158161
@classmethod
159-
def from_get(cls, payload: GetPasteResponse, /) -> Self:
162+
def from_get(cls, payload: GetPasteResponse, /, *, http: HTTPClient) -> Self:
160163
files = [File.from_data(data) for data in payload["files"]]
161164
self = cls(
165+
http=http,
162166
id=payload["id"],
163167
created_at=payload["created_at"],
164168
files=files,
@@ -176,8 +180,9 @@ def from_get(cls, payload: GetPasteResponse, /) -> Self:
176180
return self
177181

178182
@classmethod
179-
def from_create(cls, payload: CreatePasteResponse, files: Sequence[File]) -> Self:
183+
def from_create(cls, payload: CreatePasteResponse, files: Sequence[File], *, http: HTTPClient) -> Self:
180184
self = cls(
185+
http=http,
181186
id=payload["id"],
182187
created_at=payload["created_at"],
183188
files=files,
@@ -193,3 +198,9 @@ def from_create(cls, payload: CreatePasteResponse, files: Sequence[File]) -> Sel
193198
self._security = payload["safety"]
194199

195200
return self
201+
202+
async def delete(self) -> None:
203+
if not self.security_token:
204+
raise ValueError("Cannot delete a Paste with no Security Token set.")
205+
206+
await self._http.delete_paste(self.security_token)

0 commit comments

Comments
 (0)