11"""This module is a wrapper for using the SquareCloud API"""
22from __future__ import annotations
3- from threading import Thread
4- import asyncio
5- from functools import wraps
3+
64import logging
7- from datetime import datetime
85from abc import ABC , abstractmethod
9- from typing import *
10-
11- import squarecloud .errors
6+ from typing import List
127
138from .data import (
149 AppData ,
2116from .http import HTTPClient , Response
2217from .logs import logger
2318from .square import File , Application
19+ from .errors import ApplicationNotFound
2420from .types import (
2521 UserPayload ,
2622 StatusPayload ,
3026)
3127
3228
33- # noinspection Pylint
3429class AbstractClient (ABC ):
3530 """Abstract client class"""
3631
@@ -39,16 +34,17 @@ class AbstractClient(ABC):
3934 def api_key (self ):
4035 """get the api token"""
4136
42- # noinspection Pylint
37+
4338class Client (AbstractClient ):
4439 """A client for interacting with the SquareCloud API."""
4540
4641 def __init__ (self , api_key : str , debug : bool = True ) -> None :
47- """With this class you can manage/get information from your applications
42+ """With this class you can manage/get information from
43+ your applications
4844
4945 Args:
5046 api_key:Your API key, get in https://squarecloud.app/dashboard/me
51- debug: if True logs are generated with informations about requests
47+ debug: if True logs are generated with information about requests
5248 """
5349 self .debug = debug
5450 self ._api_key = api_key
@@ -192,8 +188,13 @@ async def app(self, app_id: str) -> Application:
192188 """
193189 result : Response = await self .__http .fetch_user_info ()
194190 payload : UserPayload = result .response
195- app_data = list (filter (lambda application : application ['id' ] == app_id , payload ['applications' ]))[0 ]
196- app : Application = Application (client = self , data = AppData (** app_data )) # type: ignore
191+ app_data = list (filter (lambda application : application ['id' ] == app_id ,
192+ payload ['applications' ]))
193+ if not app_data :
194+ raise ApplicationNotFound
195+ app_data = app_data .pop ()
196+ app : Application = Application (
197+ client = self , data = AppData (** app_data )) # type: ignore
197198 return app
198199
199200 async def all_apps (self ) -> List [Application ]:
@@ -205,6 +206,9 @@ async def all_apps(self) -> List[Application]:
205206 """
206207 result : Response = await self .__http .fetch_user_info ()
207208 payload : UserPayload = result .response
208- apps_data : List [AppData ] = [AppData (** app_data ) for app_data in payload ['applications' ]] # type: ignore
209- apps : List [Application ] = [Application (client = self , data = data ) for data in apps_data ]
209+ apps_data : List [AppData ] = [
210+ AppData (** app_data ) for app_data in # type: ignore
211+ payload ['applications' ]]
212+ apps : List [Application ] = [Application (client = self , data = data ) for data
213+ in apps_data ]
210214 return apps
0 commit comments