40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
import requests
|
|
|
|
import settings
|
|
from logger import logger_instance
|
|
|
|
|
|
class SiproClient:
|
|
_instance = None
|
|
|
|
def __new__(cls, *args, **kwargs):
|
|
if not cls._instance:
|
|
cls._instance = super(SiproClient, cls).__new__(cls)
|
|
return cls._instance
|
|
|
|
def __init__(self, api_url: str, token: str):
|
|
if not hasattr(self, 'initialized'):
|
|
self.api_url = api_url
|
|
self.token = token
|
|
self.initialized = True
|
|
logger_instance.info('SiproClient successfully initialized')
|
|
|
|
def method(self, http_method: str, method: str, data: dict = None):
|
|
url = self.api_url + '/assemblr' + method
|
|
headers = {'Authorization': self.token}
|
|
return requests.request(http_method, url, headers=headers, json=data).json()
|
|
|
|
def ping(self) -> str:
|
|
return self.method('GET', '/ping').get('response')
|
|
|
|
|
|
sipro_config = {
|
|
'api_url': settings.SIPRO_API_URL,
|
|
'token': settings.SIPRO_API_TOKEN,
|
|
}
|
|
sipro_client = SiproClient(**sipro_config)
|
|
|
|
|
|
def get_client() -> SiproClient:
|
|
return sipro_client
|