ebanutsya
This commit is contained in:
		
							
								
								
									
										1
									
								
								sipro/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								sipro/__init__.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
from sipro import api
 | 
			
		||||
							
								
								
									
										0
									
								
								sipro/api/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								sipro/api/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										10
									
								
								sipro/api/barcode.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								sipro/api/barcode.py
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										39
									
								
								sipro/api/client.py
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										10
									
								
								sipro/api/orders.py
									
									
									
									
									
										Normal 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
 | 
			
		||||
		Reference in New Issue
	
	Block a user