Skip to content

Commit 3236878

Browse files
new error "ApplicationNotFound" added, raised when an application is not found
1 parent 4390b7f commit 3236878

File tree

6 files changed

+36
-22
lines changed

6 files changed

+36
-22
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,7 @@ dmypy.json
135135

136136
# vscode
137137
.vscode/
138+
139+
# Other files
140+
.gitignore
141+
.pylintrc

squarecloud/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from .client import Client
22
from .square import File
3+
from .errors import *

squarecloud/client.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
"""This module is a wrapper for using the SquareCloud API"""
22
from __future__ import annotations
3-
from threading import Thread
4-
import asyncio
5-
from functools import wraps
3+
64
import logging
7-
from datetime import datetime
85
from abc import ABC, abstractmethod
9-
from typing import *
10-
11-
import squarecloud.errors
6+
from typing import List
127

138
from .data import (
149
AppData,
@@ -21,6 +16,7 @@
2116
from .http import HTTPClient, Response
2217
from .logs import logger
2318
from .square import File, Application
19+
from .errors import ApplicationNotFound
2420
from .types import (
2521
UserPayload,
2622
StatusPayload,
@@ -30,7 +26,6 @@
3026
)
3127

3228

33-
# noinspection Pylint
3429
class 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+
4338
class 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

squarecloud/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ class NotFoundError(RequestError):
1616

1717
class BadRequestError(RequestError):
1818
"""raises when a request returns a 400 response"""
19+
20+
21+
class ApplicationNotFound(SquareException):
22+
"""raises when an application is not found"""

squarecloud/http.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55

66
import aiohttp
77

8-
from .errors import RequestError, AuthenticationFailure, NotFoundError, BadRequestError
8+
from .errors import (
9+
RequestError,
10+
AuthenticationFailure,
11+
NotFoundError,
12+
BadRequestError
13+
)
914
from .logs import logger
1015
from .square import File
1116
from .types import RawResponseData
@@ -71,7 +76,7 @@ async def request(self, route: Route, **kwargs) -> Response:
7176
if route.method == 'POST':
7277
kwargs['skip_auto_headers'] = {'Content-Type'}
7378

74-
if 'file' in kwargs:
79+
if route.endpoint == 'COMMIT':
7580
del kwargs['skip_auto_headers']
7681
file = kwargs['file']
7782
kwargs.pop('file')

squarecloud/square.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ async def delete(self):
139139
"""delete the application"""
140140
await self.__client.delete_app(self.id)
141141

142-
async def commit(self, file: File):
142+
async def commit(self, file: File, restart: bool = True):
143143
"""commit the application"""
144144
await self.__client.commit(self.id, file=file)
145-
#
146-
# class Logs:
147-
# def __init__(self, Logs: Log):
148-
# self._logs:

0 commit comments

Comments
 (0)