forked from LiveCarta/LiveCartaMeta
24 lines
575 B
Python
24 lines
575 B
Python
import json
|
|
import requests
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class SenderComponent(BaseModel):
|
|
api_url: str
|
|
api_key: str
|
|
|
|
def __generate_key(self):
|
|
return 'Bearer {key}'.format(key=self.api_key)
|
|
|
|
def __headers(self):
|
|
return {
|
|
'Authorization': self.__generate_key(),
|
|
'Content-type': 'application/json',
|
|
}
|
|
|
|
def send_data(self, data):
|
|
headers = self.__headers()
|
|
response = requests.post(self.api_url + 'data', data=json.dumps(data), headers=headers)
|
|
return response.status_code == 200
|