ebanutsya

This commit is contained in:
2023-10-27 06:04:15 +03:00
parent 56792b892d
commit 1d2ee676ff
19 changed files with 196 additions and 13 deletions

0
sipro/api/__init__.py Normal file
View File

10
sipro/api/barcode.py Normal file
View File

@@ -0,0 +1,10 @@
from sipro.api.client import get_client
client = get_client()
router = '/barcode'
def get_products_by_barcode(barcode: str) -> list[dict]:
method = f'{router}/getProducts?barcode={barcode}'
response = client.method('GET', method)
return response

39
sipro/api/client.py Normal file
View File

@@ -0,0 +1,39 @@
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

10
sipro/api/orders.py Normal file
View File

@@ -0,0 +1,10 @@
from sipro.api.client import get_client
client = get_client()
router = '/orders'
def get_orders_by_supplier_product_id(supplier_product_id: str) -> list[dict]:
method = f'{router}/getBySupplierProductId?supplierProductId={supplier_product_id}'
response = client.method('GET', method)
return response