diff --git a/async_appwrite/services/async_account.py b/async_appwrite/services/async_account.py index 47e70b8..8603a16 100644 --- a/async_appwrite/services/async_account.py +++ b/async_appwrite/services/async_account.py @@ -19,9 +19,7 @@ async def get(self): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -87,9 +85,7 @@ async def list_identities(self, queries=None): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -138,9 +134,7 @@ async def list_logs(self, queries=None): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -281,9 +275,7 @@ async def list_mfa_factors(self): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -296,9 +288,7 @@ async def get_mfa_recovery_codes(self): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -403,9 +393,7 @@ async def get_prefs(self): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -487,9 +475,7 @@ async def list_sessions(self): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -628,9 +614,7 @@ async def get_session(self, session_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -755,9 +739,7 @@ async def create_o_auth2_token( return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, response_type="location", ) diff --git a/async_appwrite/services/async_storage.py b/async_appwrite/services/async_storage.py index 90a349c..606e4aa 100644 --- a/async_appwrite/services/async_storage.py +++ b/async_appwrite/services/async_storage.py @@ -20,9 +20,7 @@ async def list_buckets(self, queries=None, search=None): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -82,9 +80,7 @@ async def get_bucket(self, bucket_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -167,9 +163,7 @@ async def list_files(self, bucket_id, queries=None, search=None): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -228,9 +222,7 @@ async def get_file(self, bucket_id, file_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -300,9 +292,7 @@ async def get_file_download(self, bucket_id, file_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -350,9 +340,7 @@ async def get_file_preview( return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -373,8 +361,6 @@ async def get_file_view(self, bucket_id, file_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) diff --git a/async_appwrite/services/async_teams.py b/async_appwrite/services/async_teams.py index 025a33c..f0e4551 100644 --- a/async_appwrite/services/async_teams.py +++ b/async_appwrite/services/async_teams.py @@ -20,9 +20,7 @@ async def list(self, queries=None, search=None): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -63,9 +61,7 @@ async def get(self, team_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -128,9 +124,7 @@ async def list_memberships(self, team_id, queries=None, search=None): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -182,9 +176,7 @@ async def get_membership(self, team_id, membership_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -284,9 +276,7 @@ async def get_prefs(self, team_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) diff --git a/async_appwrite/services/async_tokens.py b/async_appwrite/services/async_tokens.py new file mode 100644 index 0000000..7782f51 --- /dev/null +++ b/async_appwrite/services/async_tokens.py @@ -0,0 +1,214 @@ +from ..async_service import AsyncService +from typing import List, Dict, Any, Optional +from appwrite.exception import AppwriteException +from appwrite.utils.deprecated import deprecated + + +class Tokens(AsyncService): + def __init__(self, client) -> None: + super(Tokens, self).__init__(client) + + async def list( + self, + bucket_id: str, + file_id: str, + queries: Optional[List[str]] = None, + total: Optional[bool] = None, + ) -> Dict[str, Any]: + """ + List all the tokens created for a specific file or bucket. You can use the query params to filter your results. + + Parameters + ---------- + bucket_id : str + Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket). + file_id : str + File unique ID. + queries : Optional[List[str]] + Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: expire + total : Optional[bool] + When set to false, the total count returned will be 0 and will not be calculated. + + Returns + ------- + Dict[str, Any] + API response as a dictionary + + Raises + ------ + AppwriteException + If API request fails + """ + + api_path = "/tokens/buckets/{bucketId}/files/{fileId}" + api_params = {} + if bucket_id is None: + raise AppwriteException('Missing required parameter: "bucket_id"') + + if file_id is None: + raise AppwriteException('Missing required parameter: "file_id"') + + api_path = api_path.replace("{bucketId}", bucket_id) + api_path = api_path.replace("{fileId}", file_id) + + if queries is not None: + api_params["queries"] = queries + if total is not None: + api_params["total"] = total + + return await self.client.call("get", api_path, {}, api_params) + + async def create_file_token( + self, bucket_id: str, file_id: str, expire: Optional[str] = None + ) -> Dict[str, Any]: + """ + Create a new token. A token is linked to a file. Token can be passed as a request URL search parameter. + + Parameters + ---------- + bucket_id : str + Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket). + file_id : str + File unique ID. + expire : Optional[str] + Token expiry date + + Returns + ------- + Dict[str, Any] + API response as a dictionary + + Raises + ------ + AppwriteException + If API request fails + """ + + api_path = "/tokens/buckets/{bucketId}/files/{fileId}" + api_params = {} + if bucket_id is None: + raise AppwriteException('Missing required parameter: "bucket_id"') + + if file_id is None: + raise AppwriteException('Missing required parameter: "file_id"') + + api_path = api_path.replace("{bucketId}", bucket_id) + api_path = api_path.replace("{fileId}", file_id) + + api_params["expire"] = expire + + return await self.client.call( + "post", + api_path, + { + "content-type": "application/json", + }, + api_params, + ) + + async def get(self, token_id: str) -> Dict[str, Any]: + """ + Get a token by its unique ID. + + Parameters + ---------- + token_id : str + Token ID. + + Returns + ------- + Dict[str, Any] + API response as a dictionary + + Raises + ------ + AppwriteException + If API request fails + """ + + api_path = "/tokens/{tokenId}" + api_params = {} + if token_id is None: + raise AppwriteException('Missing required parameter: "token_id"') + + api_path = api_path.replace("{tokenId}", token_id) + + return await self.client.call("get", api_path, {}, api_params) + + async def update( + self, token_id: str, expire: Optional[str] = None + ) -> Dict[str, Any]: + """ + Update a token by its unique ID. Use this endpoint to update a token's expiry date. + + Parameters + ---------- + token_id : str + Token unique ID. + expire : Optional[str] + File token expiry date + + Returns + ------- + Dict[str, Any] + API response as a dictionary + + Raises + ------ + AppwriteException + If API request fails + """ + + api_path = "/tokens/{tokenId}" + api_params = {} + if token_id is None: + raise AppwriteException('Missing required parameter: "token_id"') + + api_path = api_path.replace("{tokenId}", token_id) + + api_params["expire"] = expire + + return await self.client.call( + "patch", + api_path, + { + "content-type": "application/json", + }, + api_params, + ) + + async def delete(self, token_id: str) -> Dict[str, Any]: + """ + Delete a token by its unique ID. + + Parameters + ---------- + token_id : str + Token ID. + + Returns + ------- + Dict[str, Any] + API response as a dictionary + + Raises + ------ + AppwriteException + If API request fails + """ + + api_path = "/tokens/{tokenId}" + api_params = {} + if token_id is None: + raise AppwriteException('Missing required parameter: "token_id"') + + api_path = api_path.replace("{tokenId}", token_id) + + return await self.client.call( + "delete", + api_path, + { + "content-type": "application/json", + }, + api_params, + ) diff --git a/async_appwrite/services/async_users.py b/async_appwrite/services/async_users.py index ee3c7c8..f266021 100644 --- a/async_appwrite/services/async_users.py +++ b/async_appwrite/services/async_users.py @@ -20,9 +20,7 @@ async def list(self, queries=None, search=None): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -117,9 +115,7 @@ async def list_identities(self, queries=None, search=None): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -352,9 +348,7 @@ async def get(self, user_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -462,9 +456,7 @@ async def list_logs(self, user_id, queries=None): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -481,9 +473,7 @@ async def list_memberships(self, user_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -566,9 +556,7 @@ async def get_mfa_recovery_codes(self, user_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -695,9 +683,7 @@ async def get_prefs(self, user_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -738,9 +724,7 @@ async def list_sessions(self, user_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -844,9 +828,7 @@ async def list_targets(self, user_id, queries=None): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, ) @@ -903,9 +885,7 @@ async def get_target(self, user_id, target_id): return await self.client.call( "get", api_path, - { - "content-type": "application/json", - }, + {}, api_params, )