Skip to content

Commit

Permalink
feat: 调整用户 API 响应格式
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowsSov8forUs committed May 13, 2024
1 parent 66eeb47 commit c124b54
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 45 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='tsugu-api-python',
version='1.0.1',
version='1.0.2',
author='WindowsSov8',
author_email='[email protected]',
description='Tsugu BanGDream Bot 的功能 API 统合包',
Expand Down
10 changes: 5 additions & 5 deletions tsugu_api/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class _Player(TypedDict):
id: int
server: _Server

_Status: TypeAlias = Literal['success', 'failure']
_Status: TypeAlias = Literal['success', 'failed']
'''响应状态'''

class _SubmitResponse(TypedDict):
Expand Down Expand Up @@ -90,7 +90,7 @@ class _TsuguUser(TypedDict):
car: bool
server_list: list[_TsuguUserServer]

class _UserDataResponse(TypedDict):
class _GetUserDataResponse(TypedDict):
'''`/user/getUserData` 响应结果'''
status: _Status
data: Union[str, _TsuguUser]
Expand All @@ -104,7 +104,7 @@ class _Update(TypedDict):
car: NotRequired[bool]
server_list: NotRequired[list[_TsuguUserServer]]

class _UpdateResponse(TypedDict):
class _ChangeUserDataResponse(TypedDict):
'''`/user/changeUserData` 响应结果'''
status: _Status
data: NotRequired[str]
Expand All @@ -113,12 +113,12 @@ class _VerifyCode(TypedDict):
'''验证码'''
verifyCode: int

class _BindResponse(TypedDict):
class _BindPlayerRequestResponse(TypedDict):
'''`/user/bindPlayerRequest` 绑定响应'''
status: _Status
data: Union[str, _VerifyCode]

class _VerificationResponse(TypedDict):
class _BindPlayerVerificationResponse(TypedDict):
'''`/user/bindPlayerVerification` 响应结果'''
status: _Status
data: str
29 changes: 12 additions & 17 deletions tsugu_api/_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@
from tsugu_api._network import Api
from tsugu_api._typing import (
_Update,
_Response,
_ServerId,
_BindResponse,
_UpdateResponse,
_UserDataResponse,
_VerificationResponse
_GetUserDataResponse,
_ChangeUserDataResponse,
_BindPlayerRequestResponse,
_BindPlayerVerificationResponse
)

def get_user_data(platform: str, user_id: str) -> Union[_Response, _UserDataResponse]:
def get_user_data(platform: str, user_id: str) -> _GetUserDataResponse:
'''获取用户数据
参数:
platform (str): 平台名称
user_id (str): 用户 ID
返回:
_UserDataResult: 用户数据
_Response: 当请求失败时返回的数据
_GetUserDataResponse: API 返回响应
'''

# 构建 URL
Expand All @@ -39,7 +37,7 @@ def get_user_data(platform: str, user_id: str) -> Union[_Response, _UserDataResp
proxy=settings.userdata_backend_proxy
).post(data).json()

def change_user_data(platform: str, user_id: str, update: _Update) -> Union[_Response, _UpdateResponse]:
def change_user_data(platform: str, user_id: str, update: _Update) -> _ChangeUserDataResponse:
'''修改用户数据
参数:
Expand All @@ -48,8 +46,7 @@ def change_user_data(platform: str, user_id: str, update: _Update) -> Union[_Res
update (_Update): 更新数据
返回:
_UpdateResult: 更新结果
_Response: 当请求失败时返回的数据
_ChangeUserDataResponse: API 返回响应
'''

# 构建 URL
Expand All @@ -73,7 +70,7 @@ def bind_player_request(
user_id: str,
server: _ServerId,
bind_type: bool
) -> Union[_Response, _BindResponse]:
) -> _BindPlayerRequestResponse:
'''绑定玩家请求
参数:
Expand All @@ -83,8 +80,7 @@ def bind_player_request(
bind_type (bool): 绑定类型, `true` 为绑定, `false` 为解绑
返回:
_BindResponse: 请求返回数据
_Response: 当请求失败时返回的数据
_BindPlayerRequestResponse: 请求返回数据
'''

# 构建 URL
Expand All @@ -110,7 +106,7 @@ def bind_player_verification(
server: _ServerId,
player_id: int,
bind_type: bool
) -> Union[_Response, _VerificationResponse]:
) -> _BindPlayerVerificationResponse:
'''绑定玩家验证
参数:
Expand All @@ -121,8 +117,7 @@ def bind_player_verification(
bind_type (bool): 绑定类型, `true` 为绑定, `false` 为解绑
返回:
_VerificationResponse: 验证返回数据
_Response: 当请求失败时返回的数据
_BindPlayerVerificationResponse: 验证返回数据
'''

# 构建 URL
Expand Down
10 changes: 5 additions & 5 deletions tsugu_api_async/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _Player(TypedDict):
id: int
server: _Server

_Status: TypeAlias = Literal['success', 'failure']
_Status: TypeAlias = Literal['success', 'failed']
'''响应状态'''

class _SubmitResponse(TypedDict):
Expand Down Expand Up @@ -95,7 +95,7 @@ class _TsuguUser(TypedDict):
car: bool
server_list: list[_TsuguUserServer]

class _UserDataResponse(TypedDict):
class _GetUserDataResponse(TypedDict):
'''`/user/getUserData` 响应结果'''
status: _Status
data: Union[str, _TsuguUser]
Expand All @@ -109,7 +109,7 @@ class _Update(TypedDict):
car: NotRequired[bool]
server_list: NotRequired[list[_TsuguUserServer]]

class _UpdateResponse(TypedDict):
class _ChangeUserDataResponse(TypedDict):
'''`/user/changeUserData` 响应结果'''
status: _Status
data: NotRequired[str]
Expand All @@ -118,12 +118,12 @@ class _VerifyCode(TypedDict):
'''验证码'''
verifyCode: int

class _BindResponse(TypedDict):
class _BindPlayerRequestResponse(TypedDict):
'''`/user/bindPlayerRequest` 绑定响应'''
status: _Status
data: Union[str, _VerifyCode]

class _VerificationResponse(TypedDict):
class _BindPlayerVerificationResponse(TypedDict):
'''`/user/bindPlayerVerification` 响应结果'''
status: _Status
data: str
29 changes: 12 additions & 17 deletions tsugu_api_async/_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@
from tsugu_api_async._network import Api
from tsugu_api_async._typing import (
_Update,
_Response,
_ServerId,
_BindResponse,
_UpdateResponse,
_UserDataResponse,
_VerificationResponse
_GetUserDataResponse,
_ChangeUserDataResponse,
_BindPlayerRequestResponse,
_BindPlayerVerificationResponse
)

async def get_user_data(platform: str, user_id: str) -> Union[_Response, _UserDataResponse]:
async def get_user_data(platform: str, user_id: str) -> _GetUserDataResponse:
'''获取用户数据
参数:
platform (str): 平台名称
user_id (str): 用户 ID
返回:
_UserDataResult: 用户数据
_Response: 当请求失败时返回的数据
_GetUserDataResponse: API 返回响应
'''

# 构建 URL
Expand All @@ -43,7 +41,7 @@ async def get_user_data(platform: str, user_id: str) -> Union[_Response, _UserDa
if isinstance(response, Response): return response.json()
return await response.json()

async def change_user_data(platform: str, user_id: str, update: _Update) -> Union[_Response, _UpdateResponse]:
async def change_user_data(platform: str, user_id: str, update: _Update) -> _ChangeUserDataResponse:
'''修改用户数据
参数:
Expand All @@ -52,8 +50,7 @@ async def change_user_data(platform: str, user_id: str, update: _Update) -> Unio
update (_Update): 更新数据
返回:
_UpdateResult: 更新结果
_Response: 当请求失败时返回的数据
_ChangeUserDataResponse: API 返回响应
'''

# 构建 URL
Expand All @@ -79,7 +76,7 @@ async def bind_player_request(
user_id: str,
server: _ServerId,
bind_type: bool
) -> Union[_Response, _BindResponse]:
) -> _BindPlayerRequestResponse:
'''绑定玩家请求
参数:
Expand All @@ -89,8 +86,7 @@ async def bind_player_request(
bind_type (bool): 绑定类型, `true` 为绑定, `false` 为解绑
返回:
_BindResponse: 请求返回数据
_Response: 当请求失败时返回的数据
_BindPlayerRequestResponse: 请求返回数据
'''

# 构建 URL
Expand Down Expand Up @@ -118,7 +114,7 @@ async def bind_player_verification(
server: _ServerId,
player_id: int,
bind_type: bool
) -> Union[_Response, _VerificationResponse]:
) -> _BindPlayerVerificationResponse:
'''绑定玩家验证
参数:
Expand All @@ -129,8 +125,7 @@ async def bind_player_verification(
bind_type (bool): 绑定类型, `true` 为绑定, `false` 为解绑
返回:
_VerificationResponse: 验证返回数据
_Response: 当请求失败时返回的数据
_BindPlayerVerificationResponse: 验证返回数据
'''

# 构建 URL
Expand Down

0 comments on commit c124b54

Please sign in to comment.