mirror of
https://github.com/MrSedan/neuro-reply-bot-reworked.git
synced 2026-01-14 13:39:42 +03:00
added proxyapi
This commit is contained in:
1
proxyapi/__init__.py
Normal file
1
proxyapi/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from ._proxyapi import proxyapi
|
||||
30
proxyapi/_methods/operation.py
Normal file
30
proxyapi/_methods/operation.py
Normal file
@@ -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()]
|
||||
31
proxyapi/_methods/user.py
Normal file
31
proxyapi/_methods/user.py
Normal file
@@ -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()]
|
||||
7
proxyapi/_proxyapi.py
Normal file
7
proxyapi/_proxyapi.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from ._methods.user import User
|
||||
from ._methods.operation import Operation
|
||||
|
||||
|
||||
class proxyapi():
|
||||
user = User()
|
||||
operation = Operation()
|
||||
2
proxyapi/types/__init__.py
Normal file
2
proxyapi/types/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from ._user import User
|
||||
from ._operation import Operation
|
||||
61
proxyapi/types/_operation.py
Normal file
61
proxyapi/types/_operation.py
Normal file
@@ -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
|
||||
36
proxyapi/types/_user.py
Normal file
36
proxyapi/types/_user.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user