Add basic API functions and working account.auth method
This commit is contained in:
29
api/api_utils.py
Normal file
29
api/api_utils.py
Normal 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
|
||||
Reference in New Issue
Block a user