diff --git a/mystbin/client.py b/mystbin/client.py index 5a1c25f..ddb48bb 100755 --- a/mystbin/client.py +++ b/mystbin/client.py @@ -84,7 +84,7 @@ async def create_paste( The paste that was created. """ data = await self.http.create_paste(files=files, password=password, expires=expires) - return Paste.from_create(data, files=files) + return Paste.from_create(data, files=files, http=self.http) async def delete_paste(self, security_token: str, /) -> None: """|coro| @@ -130,4 +130,4 @@ async def get_paste(self, paste_id: str, *, password: str | None = None, raw: bo data = await self.http.get_paste(paste_id=paste_id, password=password) if raw: return [item["content"] for item in data["files"]] - return Paste.from_get(data) + return Paste.from_get(data, http=self.http) diff --git a/mystbin/paste.py b/mystbin/paste.py index 745c431..ddb9923 100755 --- a/mystbin/paste.py +++ b/mystbin/paste.py @@ -30,7 +30,8 @@ from typing_extensions import Self - from mystbin.types.responses import CreatePasteResponse, FileResponse, GetPasteResponse + from .http import HTTPClient + from .types.responses import CreatePasteResponse, FileResponse, GetPasteResponse __all__ = ( @@ -126,9 +127,11 @@ class Paste: "_security", "_expires", "_views", + "_http", ) - def __init__(self, *, id: str, created_at: str, files: Sequence[File]) -> None: + def __init__(self, *, http: HTTPClient, id: str, created_at: str, files: Sequence[File]) -> None: + self._http: HTTPClient = http self.id: str = id self.created_at: datetime.datetime = datetime.datetime.fromisoformat(created_at) self.files: Sequence[File] = files @@ -156,9 +159,10 @@ def security_token(self) -> str | None: return self._security @classmethod - def from_get(cls, payload: GetPasteResponse, /) -> Self: + def from_get(cls, payload: GetPasteResponse, /, *, http: HTTPClient) -> Self: files = [File.from_data(data) for data in payload["files"]] self = cls( + http=http, id=payload["id"], created_at=payload["created_at"], files=files, @@ -176,8 +180,9 @@ def from_get(cls, payload: GetPasteResponse, /) -> Self: return self @classmethod - def from_create(cls, payload: CreatePasteResponse, files: Sequence[File]) -> Self: + def from_create(cls, payload: CreatePasteResponse, files: Sequence[File], *, http: HTTPClient) -> Self: self = cls( + http=http, id=payload["id"], created_at=payload["created_at"], files=files, @@ -193,3 +198,9 @@ def from_create(cls, payload: CreatePasteResponse, files: Sequence[File]) -> Sel self._security = payload["safety"] return self + + async def delete(self) -> None: + if not self.security_token: + raise ValueError("Cannot delete a Paste with no Security Token set.") + + await self._http.delete_paste(self.security_token)