diff --git a/proxyapi/__init__.py b/proxyapi/__init__.py new file mode 100644 index 0000000..fe77f79 --- /dev/null +++ b/proxyapi/__init__.py @@ -0,0 +1 @@ +from ._proxyapi import proxyapi diff --git a/proxyapi/_methods/operation.py b/proxyapi/_methods/operation.py new file mode 100644 index 0000000..1f43643 --- /dev/null +++ b/proxyapi/_methods/operation.py @@ -0,0 +1,30 @@ +from aiohttp import ClientSession + +import proxyapi.types as proxyTypes + +from neuroapi._methods.api_method import ApiMethod + + +class Operation(ApiMethod): + + async def add(self, user_name: str): + payload = {'userName': user_name} + async with ClientSession() as session: + response = await session.post( + self.api_url+'/proxy/operation/add', data=payload) + data = await response.json() + if 'statusCode' in data: + raise Exception(data['message']) + return proxyTypes.Operation.from_dict(data) + + async def get(self, user_name: str): + async with ClientSession() as session: + response = await session.get( + self.api_url + f'/proxy/operation/get/{user_name}') + return [proxyTypes.Operation.from_dict(data) for data in await response.json()] + + async def get_all(self): + async with ClientSession() as session: + response = await session.get( + self.api_url + f'/proxy/operation/get-all') + return [proxyTypes.Operation.from_dict(data) for data in await response.json()] diff --git a/proxyapi/_methods/user.py b/proxyapi/_methods/user.py new file mode 100644 index 0000000..363032c --- /dev/null +++ b/proxyapi/_methods/user.py @@ -0,0 +1,31 @@ +from aiohttp import ClientSession + +import proxyapi.types as proxyTypes + +from neuroapi._methods.api_method import ApiMethod + + +class User(ApiMethod): + + async def new_user(self, user_name: str, description: str, link: str, user_id: str): + payload = {'userName': user_name, 'description': description, + 'link': link, 'user_id': user_id} + async with ClientSession() as session: + response = await session.post(self.api_url+'/proxy/new-user', data=payload) + data = await response.json() + if 'statusCode' in data: + raise Exception(data['message']) + return proxyTypes.User.from_dict(data) + + async def get_user(self, user_name: str): + async with ClientSession() as session: + response = await session.get(self.api_url+f'/proxy/get-user/{user_name}') + data = await response.json() + if 'statusCode' in data: + raise Exception(data['message']) + return proxyTypes.User.from_dict(data) + + async def get_all_users(self): + async with ClientSession() as session: + response = await session.get(self.api_url+'/proxy/get-all-users') + return [proxyTypes.User.from_dict(data) for data in await response.json()] diff --git a/proxyapi/_proxyapi.py b/proxyapi/_proxyapi.py new file mode 100644 index 0000000..860469e --- /dev/null +++ b/proxyapi/_proxyapi.py @@ -0,0 +1,7 @@ +from ._methods.user import User +from ._methods.operation import Operation + + +class proxyapi(): + user = User() + operation = Operation() diff --git a/proxyapi/types/__init__.py b/proxyapi/types/__init__.py new file mode 100644 index 0000000..805c3de --- /dev/null +++ b/proxyapi/types/__init__.py @@ -0,0 +1,2 @@ +from ._user import User +from ._operation import Operation diff --git a/proxyapi/types/_operation.py b/proxyapi/types/_operation.py new file mode 100644 index 0000000..ec1bb2b --- /dev/null +++ b/proxyapi/types/_operation.py @@ -0,0 +1,61 @@ +from dataclasses import dataclass +from uuid import UUID +from datetime import datetime +from typing import Any +from neuroapi.types._helpers import * + + +@dataclass +class User: + uuid: UUID + user_name: str + description: str + link: str + connect_date: datetime + user_id: None + + @staticmethod + def from_dict(obj: Any) -> 'User': + assert isinstance(obj, dict) + uuid = UUID(obj.get("uuid")) + user_name = from_str(obj.get("userName")) + description = from_str(obj.get("description")) + link = from_str(obj.get("link")) + connect_date = from_datetime(obj.get("connectDate")) + user_id = from_none(obj.get("user_id")) + return User(uuid, user_name, description, link, connect_date, user_id) + + def to_dict(self) -> dict: + result: dict = {} + result["uuid"] = str(self.uuid) + result["userName"] = from_str(self.user_name) + result["description"] = from_str(self.description) + result["link"] = from_str(self.link) + result["connectDate"] = self.connect_date.isoformat() + result["user_id"] = from_none(self.user_id) + return result + + +@dataclass +class Operation: + pay_time: datetime + user: User + user_uuid: UUID + id: int + + @staticmethod + def from_dict(obj: Any) -> 'Operation': + assert isinstance(obj, dict) + pay_time = from_datetime(obj.get("payTime")) + user = User.from_dict(obj.get("user")) + user_uuid = UUID(obj.get("user_uuid")) + id = from_int(obj.get("id")) + return Operation(pay_time, user, user_uuid, id) + + def to_dict(self) -> dict: + result: dict = {} + result["payTime"] = self.pay_time.isoformat() + result["user"] = to_class(User, self.user) + result["user_uuid"] = str(self.user_uuid) + result["id"] = from_int(self.id) + return result diff --git a/proxyapi/types/_user.py b/proxyapi/types/_user.py new file mode 100644 index 0000000..69c38f2 --- /dev/null +++ b/proxyapi/types/_user.py @@ -0,0 +1,36 @@ +from dataclasses import dataclass +from uuid import UUID +from datetime import datetime +from typing import Any +from neuroapi.types._helpers import * + + +@dataclass +class User: + uuid: UUID + user_name: str + description: str + link: str + connect_date: datetime + user_id: str + + @staticmethod + def from_dict(obj: Any) -> 'User': + assert isinstance(obj, dict) + uuid = UUID(obj.get("uuid")) + user_name = from_str(obj.get("userName")) + description = from_str(obj.get("description")) + link = from_str(obj.get("link")) + connect_date = from_datetime(obj.get("connectDate")) + user_id = from_none(obj.get("user_id")) + return User(uuid, user_name, description, link, connect_date, user_id) + + def to_dict(self) -> dict: + result: dict = {} + result["uuid"] = str(self.uuid) + result["userName"] = from_str(self.user_name) + result["description"] = from_str(self.description) + result["link"] = from_str(self.link) + result["connectDate"] = self.connect_date.isoformat() + result["user_id"] = from_none(self.user_id) + return result