mirror of
https://github.com/shadoll/playing_now_2_mm.git
synced 2025-12-20 05:28:51 +00:00
code refactoring
This commit is contained in:
19
connectors/mattermost.py
Normal file
19
connectors/mattermost.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import requests
|
||||
|
||||
class MattermostConnector:
|
||||
def __init__(self, connection_config) -> None:
|
||||
self.url = connection_config.get("url", "https://mattermost.com")
|
||||
self.token = connection_config.get("token", "")
|
||||
self.connect(connection_config.get("user_id", "me"))
|
||||
|
||||
def connect(self, user_id):
|
||||
self.headers = {
|
||||
"Authorization": f"Bearer {self.token}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
self.url = f"{self.url}/api/v4/users/{user_id}/status/custom"
|
||||
|
||||
def send(self, data):
|
||||
response = requests.put(self.url, headers=self.headers, json=data)
|
||||
if response.status_code != 200:
|
||||
raise Exception(f"Failed to set Mattermost status: {response.content!r}")
|
||||
Reference in New Issue
Block a user