66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
from requests import request
|
||
|
||
|
||
class BotApi:
|
||
|
||
def __init__(self, host):
|
||
"""
|
||
:param host: 平台域名
|
||
"""
|
||
self.host = host
|
||
|
||
def get_access_tokens(self, bot_installer_id, jwt_token):
|
||
"""
|
||
申请授权Token
|
||
:param bot_installer_id: bot安装到某个仓库的安装id bot_install.installer_id=安装用户的id:user_id
|
||
:param jwt_token: jwt_token
|
||
:return: 返回access_token
|
||
"""
|
||
try:
|
||
url = f"{self.host}/app/installations/{bot_installer_id}/access_tokens"
|
||
headers = {
|
||
"Authorization": f"Bearer {jwt_token}"
|
||
}
|
||
response = request(method="POST", url=url, headers=headers)
|
||
access_token = response.json().get("token", "")
|
||
return access_token
|
||
except Exception as e:
|
||
raise e
|
||
|
||
def get_bot_installed_project(self, bot_installer_id, access_token):
|
||
"""
|
||
获取已安装bot仓库列表
|
||
:param bot_installer_id: bot安装到某个仓库的安装id bot_install.installer_id=安装用户的id:user_id
|
||
:param access_token:授权token
|
||
:return:
|
||
"""
|
||
try:
|
||
url = f"{self.host}/installations/{bot_installer_id}/repositories.json"
|
||
headers = {
|
||
"Content-Type": "application/json",
|
||
"Authorization": f"Bearer {access_token}"
|
||
}
|
||
response = request(method="GET", url=url, headers=headers)
|
||
return response
|
||
except Exception as e:
|
||
raise e
|
||
|
||
def get_installed_bot_detail(self, bot_installer_id, access_token):
|
||
"""
|
||
获取已安装bot详情
|
||
:param bot_installer_id: bot安装到某个仓库的安装id bot_install.installer_id=安装用户的id:user_id
|
||
:param access_token:授权token
|
||
:return:
|
||
"""
|
||
try:
|
||
url = f"{self.host}/app/installations/{bot_installer_id}.json"
|
||
headers = {
|
||
"Content-Type": "application/json",
|
||
"Authorization": f"Bearer {access_token}"
|
||
}
|
||
response = request(method="GET", url=url, headers=headers)
|
||
return response
|
||
except Exception as e:
|
||
raise e
|
||
|