mirror of
https://github.com/DragonMinded/bemaniutils.git
synced 2026-08-25 20:04:25 -05:00
Switch to using an enum for API ID constants.
This commit is contained in:
@@ -286,10 +286,17 @@ def lookup(protoversion: str, requestgame: str, requestversion: str) -> Dict[str
|
||||
# Don't support this version!
|
||||
abort(404)
|
||||
|
||||
idtype = requestdata['type']
|
||||
ids = requestdata['ids']
|
||||
if idtype not in [APIConstants.ID_TYPE_CARD, APIConstants.ID_TYPE_SONG, APIConstants.ID_TYPE_INSTANCE, APIConstants.ID_TYPE_SERVER]:
|
||||
# Attempt to coerce ID type. If we fail, provide the correct failure message.
|
||||
idtype = None
|
||||
try:
|
||||
idtype = APIConstants(requestdata['type'])
|
||||
except ValueError:
|
||||
pass
|
||||
if idtype is None:
|
||||
raise APIException('Invalid ID type provided!')
|
||||
|
||||
# Validate the provided IDs given the ID type above.
|
||||
ids = requestdata['ids']
|
||||
if idtype == APIConstants.ID_TYPE_CARD and len(ids) == 0:
|
||||
raise APIException('Invalid number of IDs given!')
|
||||
if idtype == APIConstants.ID_TYPE_SONG and len(ids) not in [1, 2]:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from typing import List, Any, Dict
|
||||
|
||||
from bemani.api.exceptions import APIException
|
||||
from bemani.common import GameConstants
|
||||
from bemani.common import APIConstants, GameConstants
|
||||
from bemani.data import Data
|
||||
|
||||
|
||||
@@ -20,5 +20,5 @@ class BaseObject:
|
||||
self.version = version
|
||||
self.omnimix = omnimix
|
||||
|
||||
def fetch_v1(self, idtype: str, ids: List[str], params: Dict[str, Any]) -> Any:
|
||||
def fetch_v1(self, idtype: APIConstants, ids: List[str], params: Dict[str, Any]) -> Any:
|
||||
raise APIException('Object fetch not supported for this version!')
|
||||
|
||||
@@ -192,7 +192,7 @@ class CatalogObject(BaseObject):
|
||||
else:
|
||||
return self.version
|
||||
|
||||
def fetch_v1(self, idtype: str, ids: List[str], params: Dict[str, Any]) -> Dict[str, List[Dict[str, Any]]]:
|
||||
def fetch_v1(self, idtype: APIConstants, ids: List[str], params: Dict[str, Any]) -> Dict[str, List[Dict[str, Any]]]:
|
||||
# Verify IDs
|
||||
if idtype != APIConstants.ID_TYPE_SERVER:
|
||||
raise APIException(
|
||||
|
||||
@@ -73,7 +73,7 @@ class ProfileObject(BaseObject):
|
||||
|
||||
return base
|
||||
|
||||
def fetch_v1(self, idtype: str, ids: List[str], params: Dict[str, Any]) -> List[Dict[str, Any]]:
|
||||
def fetch_v1(self, idtype: APIConstants, ids: List[str], params: Dict[str, Any]) -> List[Dict[str, Any]]:
|
||||
# Fetch the profiles
|
||||
profiles: List[Tuple[UserID, ValidatedDict]] = []
|
||||
if idtype == APIConstants.ID_TYPE_SERVER:
|
||||
|
||||
@@ -230,7 +230,7 @@ class RecordsObject(BaseObject):
|
||||
else:
|
||||
return self.version
|
||||
|
||||
def fetch_v1(self, idtype: str, ids: List[str], params: Dict[str, Any]) -> List[Dict[str, Any]]:
|
||||
def fetch_v1(self, idtype: APIConstants, ids: List[str], params: Dict[str, Any]) -> List[Dict[str, Any]]:
|
||||
since = params.get('since')
|
||||
until = params.get('until')
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ class StatisticsObject(BaseObject):
|
||||
|
||||
return retval
|
||||
|
||||
def fetch_v1(self, idtype: str, ids: List[str], params: Dict[str, Any]) -> List[Dict[str, Any]]:
|
||||
def fetch_v1(self, idtype: APIConstants, ids: List[str], params: Dict[str, Any]) -> List[Dict[str, Any]]:
|
||||
retval: List[Dict[str, Any]] = []
|
||||
|
||||
# Fetch the attempts
|
||||
|
||||
Reference in New Issue
Block a user