Add basic API functions and working account.auth method

This commit is contained in:
2022-09-17 12:01:14 +03:00
parent 59ec0647dc
commit d51ffa0eb2
9 changed files with 262 additions and 9 deletions

29
api/api_utils.py Normal file
View File

@@ -0,0 +1,29 @@
from .api_errors import *
def __make_invalid_argument_type_error(name, value, except_type):
related = {"param_name": name, "excepted_type": "int", "value": value}
raise Exception(API_ERROR_INVALID_ARGUMENT_TYPE, related)
def api_get_param_int(params: dict, name: str, required=True, default=0):
if name in params:
try:
return int(params[name])
except:
__make_invalid_argument_type_error(name, params[name], "int")
if required:
raise Exception(API_ERROR_MISSING_ARGUMENT, name)
return default
def api_get_param_str(params: dict, name: str, required=True, default=""):
if name in params:
return params[name]
if required:
raise Exception(API_ERROR_MISSING_ARGUMENT, name)
return default