36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
from server.services.device import DeviceProfile
|
|
from server.services.http import http
|
|
|
|
API_BASE = "https://apis.raptdrama.com"
|
|
|
|
|
|
class RaptApi:
|
|
def guest_token(self, device: DeviceProfile) -> str:
|
|
data = self._post("/app/open/autologin", "", device, {})
|
|
token = data.get("token") or ""
|
|
if not token:
|
|
raise RuntimeError("游客登录没有返回 token")
|
|
return token
|
|
|
|
def email_token(self, email: str, password: str, device: DeviceProfile) -> str:
|
|
data = self._post("/app/open/emailLogin", "", device, {
|
|
"email": email,
|
|
"password": password,
|
|
})
|
|
token = data.get("token") or ""
|
|
if not token:
|
|
raise RuntimeError("邮箱登录没有返回 token")
|
|
return token
|
|
|
|
def user_info(self, token: str, device: DeviceProfile) -> dict:
|
|
data = self._post("/app/user/getUserInfo", token, device, {})
|
|
data.pop("token", None)
|
|
data.pop("accessToken", None)
|
|
return data
|
|
|
|
def _post(self, path: str, token: str, device: DeviceProfile, body: dict) -> dict:
|
|
return http.request_json("POST", API_BASE + path, token, device, body)
|
|
|
|
|
|
rapt = RaptApi()
|