From 01f97d40b6aa2dfaceb18a6e8762d68c4830cf79 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Fri, 22 Dec 2023 13:50:57 -0500 Subject: [PATCH] feat: added get_files method --- pyzipline/zipline.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pyzipline/zipline.py b/pyzipline/zipline.py index a8cce0a..86681a8 100644 --- a/pyzipline/zipline.py +++ b/pyzipline/zipline.py @@ -191,6 +191,39 @@ class ZiplineApi: raise NotFound('image not found on filesystem') raise PyZiplineError(f"{result.status_code}: {result.message}\n{result.data}") + def get_files(self, favorite: bool = False, media_only: bool = False) -> list[File]: + """Get a list of the files uploaded by the authenticated user + + /// admonition | Requires Authentication + type: warning + /// + + Args: + favorite (bool): Whether or not to return only favorite files + media_only (bool): Whether or not to return only media files + + Raises: + Forbidden: The user is not authenticated + PyZiplineError: Raised if the API changes, causing a breaking change in this method + + Returns: + File: List of files uploaded by the authenticated user + """ + params = {} + if favorite: + params['favorite'] = favorite + if media_only: + params['media_only'] = media_only + result: Result = self._rest_adapter.get(endpoint="/user/files", params=params) + if result.status_code == 200: + files = [] + for file in result.data: + f = File(**file) + files.append(f) + return files + if result.status_code == 401: + raise Forbidden(result.message) + def get_self(self) -> User: """Get the currently authenticated user