Skip to content

Commit

Permalink
rebase: client, utils & exceptions import
Browse files Browse the repository at this point in the history
  • Loading branch information
201st-Luka committed Oct 2, 2023
1 parent d6403f6 commit b5b2b7a
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 8 deletions.
34 changes: 27 additions & 7 deletions pyclasher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,35 @@

__version__ = '1.0.0'

from .api import *
from .api.bulk_requests import *
from .api.requests import *
from .client import Client
from .exceptions import (
PyClasherException, ApiException, ApiExceptions, UnknownApiException,
MISSING, Missing, RequestNotDone, RequestTimeout, BadRequest, NotFound,
Throttled, Maintenance, AccessDenied, NoClient, InvalidClientId,
ClientIsRunning, ClientIsNotRunning, ClientRunningOverwrite,
ClientAlreadyInitialised, LoginNotDone, InvalidLoginData, InvalidType,
InvalidTimeFormat, InvalidSeasonFormat, NoneToken
PyClasherException,
ApiException,
ApiExceptions,
UnknownApiException,
MISSING,
Missing,
RequestNotDone,
RequestTimeout,
BadRequest,
NotFound,
Throttled,
Maintenance,
AccessDenied,
NoClient,
InvalidClientId,
ClientIsRunning,
ClientIsNotRunning,
ClientRunningOverwrite,
ClientAlreadyInitialised,
LoginNotDone,
InvalidLoginData,
InvalidType,
InvalidTimeFormat,
InvalidSeasonFormat,
NoneToken
)

__all__ = (
Expand Down
5 changes: 5 additions & 0 deletions pyclasher/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
from pyclasher.utils.login import Login


__all__ = (
'Client',
)


global_client_id = 0
"""Global variable for counting and identifying clients"""

Expand Down
6 changes: 6 additions & 0 deletions pyclasher/client/client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ from typing import Iterable
from ..exceptions import MISSING
from .request_queue import PQueue


__all__ = (
'Client',
)


global_client_id: int = ...


Expand Down
6 changes: 5 additions & 1 deletion pyclasher/client/request_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from pyclasher.utils import ExecutionTimer


__all__ = (
'PConsumer',
)


class PConsumer:
def __init__(self, queue, token, requests_per_s, request_timeout, url):
self.queue = queue
Expand Down Expand Up @@ -55,7 +60,6 @@ async def _request(self, future, url, method, body, status, error):
error.set_result(exception)
raise exception


async def consume(self):
while True:
future, url, method, body, status, error = await self.queue.get()
Expand Down
5 changes: 5 additions & 0 deletions pyclasher/client/request_consumer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ from aiohttp import ClientSession
from .request_queue import PQueue


__all__ = (
'PConsumer',
)


class PConsumer:
"""
consumer class that consumes the requests and returns the responses of the ClashOfClans API
Expand Down
5 changes: 5 additions & 0 deletions pyclasher/client/request_queue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from asyncio import Queue


__all__ = (
'PQueue',
)


class PQueue(Queue):
async def put(self,
future,
Expand Down
5 changes: 5 additions & 0 deletions pyclasher/client/request_queue.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ from asyncio import Queue, Future
from ..utils.request_methods import RequestMethods


__all__ = (
'PQueue',
)


class PQueue(Queue):
async def put(self,
future: Future,
Expand Down
29 changes: 29 additions & 0 deletions pyclasher/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@
"""


__all__ = (
'PyClasherException',
'Missing',
'MISSING',
'LoginNotDone',
'RequestTimeout',
'InvalidLoginData',
'NotFound',
'BadRequest',
'AccessDenied',
'ApiException',
'Throttled',
'Maintenance',
'NoClient',
'NoneToken',
'InvalidType',
'UnknownApiException',
'ApiExceptions',
'InvalidClientId',
'ClientIsRunning',
'RequestNotDone',
'InvalidTimeFormat',
'InvalidSeasonFormat',
'ClientIsNotRunning',
'ClientRunningOverwrite',
'ClientAlreadyInitialised',
)


class Missing:
"""
Class of the ``MISSING`` object
Expand Down
29 changes: 29 additions & 0 deletions pyclasher/exceptions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,35 @@ from typing import Any
from .api.models import ClientError


__all__ = (
'PyClasherException',
'Missing',
'MISSING',
'LoginNotDone',
'RequestTimeout',
'InvalidLoginData',
'NotFound',
'BadRequest',
'AccessDenied',
'ApiException',
'Throttled',
'Maintenance',
'NoClient',
'NoneToken',
'InvalidType',
'UnknownApiException',
'ApiExceptions',
'InvalidClientId',
'ClientIsRunning',
'RequestNotDone',
'InvalidTimeFormat',
'InvalidSeasonFormat',
'ClientIsNotRunning',
'ClientRunningOverwrite',
'ClientAlreadyInitialised',
)


class Missing:
"""
Class of the ``MISSING`` object
Expand Down
8 changes: 8 additions & 0 deletions pyclasher/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
from .functions import snake_to_camel
from .login import Login
from .request_methods import RequestMethods


__all__ = (
'ExecutionTimer',
'snake_to_camel',
'Login',
'RequestMethods',
)
5 changes: 5 additions & 0 deletions pyclasher/utils/exectimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
from time import perf_counter


__all__ = (
'ExecutionTimer',
)


class ExecutionTimer:
def __init__(self, min_time=0):
self._min_time = min_time
Expand Down
5 changes: 5 additions & 0 deletions pyclasher/utils/exectimer.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
__all__ = (
'ExecutionTimer',
)


class ExecutionTimer:
def __init__(self, min_time: float = 0) -> None:
self._min_time = min_time
Expand Down
5 changes: 5 additions & 0 deletions pyclasher/utils/functions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
__all__ = (
'snake_to_camel',
)


def snake_to_camel(snake_str: str) -> str:
components = snake_str.split('_')
camel_str = components[0] + ''.join(
Expand Down
5 changes: 5 additions & 0 deletions pyclasher/utils/functions.pyi
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
__all__ = (
'snake_to_camel',
)


def snake_to_camel(snake_str: str) -> str:
...
5 changes: 5 additions & 0 deletions pyclasher/utils/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
from ..exceptions import MISSING, LoginNotDone, InvalidLoginData


__all__ = (
'Login',
)


class Login(LoginModel):
login_url = "https://developer.clashofclans.com/api/login"
__response = None
Expand Down
5 changes: 5 additions & 0 deletions pyclasher/utils/login.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ from ..api.models.login import LoginModel
from ..exceptions import Missing


__all__ = (
'Login',
)


class Login(LoginModel):
"""
class to log in via the ClashOfClans login API
Expand Down
5 changes: 5 additions & 0 deletions pyclasher/utils/request_methods.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from enum import Enum


__all__ = (
'RequestMethods',
)


class RequestMethods(Enum):
REQUEST = "get"
POST = "post"
5 changes: 5 additions & 0 deletions pyclasher/utils/request_methods.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from enum import Enum


__all__ = (
'RequestMethods',
)


class RequestMethods(Enum):
REQUEST = "get"
POST = "post"

0 comments on commit b5b2b7a

Please sign in to comment.