Skip to content

Commit 1315cf3

Browse files
committed
fix: search client and some baseclient functionalities
1 parent 5c75ccf commit 1315cf3

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

src/basalam_sdk/base_client.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def async_wrapper(self, *args, **kwargs):
3131
require_auth = kwargs.get('require_auth', True)
3232
if not require_auth:
3333
return await func(self, *args, **kwargs)
34-
34+
3535
try:
3636
return await func(self, *args, **kwargs)
3737
except BasalamAuthError:
@@ -45,7 +45,7 @@ def sync_wrapper(self, *args, **kwargs):
4545
require_auth = kwargs.get('require_auth', True)
4646
if not require_auth:
4747
return func(self, *args, **kwargs)
48-
48+
4949
try:
5050
return func(self, *args, **kwargs)
5151
except BasalamAuthError:
@@ -104,10 +104,11 @@ def _get_headers(self, custom_headers: Optional[Dict[str, str]] = None) -> Dict[
104104

105105
return headers
106106

107-
async def _get_client(self, custom_headers: Optional[Dict[str, str]] = None, require_auth: bool = True) -> httpx.AsyncClient:
107+
async def _get_client(self, custom_headers: Optional[Dict[str, str]] = None,
108+
require_auth: bool = True) -> httpx.AsyncClient:
108109
"""Get an async HTTP client with proper configuration."""
109110
headers = self._get_headers(custom_headers)
110-
111+
111112
if require_auth:
112113
auth_headers = await self.auth.get_auth_headers()
113114
headers.update(auth_headers)
@@ -118,10 +119,11 @@ async def _get_client(self, custom_headers: Optional[Dict[str, str]] = None, req
118119
follow_redirects=True,
119120
)
120121

121-
def _get_client_sync(self, custom_headers: Optional[Dict[str, str]] = None, require_auth: bool = True) -> httpx.Client:
122+
def _get_client_sync(self, custom_headers: Optional[Dict[str, str]] = None,
123+
require_auth: bool = True) -> httpx.Client:
122124
"""Get a synchronous HTTP client with proper configuration."""
123125
headers = self._get_headers(custom_headers)
124-
126+
125127
if require_auth:
126128
auth_headers = self.auth.get_auth_headers_sync()
127129
headers.update(auth_headers)
@@ -259,7 +261,8 @@ async def _get(
259261
require_auth: bool = True,
260262
) -> Union[Dict[str, Any], List[Dict[str, Any]], T]:
261263
"""Make a GET request."""
262-
return await self.request("GET", path, params=params, headers=headers, response_model=response_model, require_auth=require_auth)
264+
return await self.request("GET", path, params=params, headers=headers, response_model=response_model,
265+
require_auth=require_auth)
263266

264267
def _get_sync(
265268
self,
@@ -270,7 +273,8 @@ def _get_sync(
270273
require_auth: bool = True,
271274
) -> Union[Dict[str, Any], List[Dict[str, Any]], T]:
272275
"""Make a synchronous GET request."""
273-
return self.request_sync("GET", path, params=params, headers=headers, response_model=response_model, require_auth=require_auth)
276+
return self.request_sync("GET", path, params=params, headers=headers, response_model=response_model,
277+
require_auth=require_auth)
274278

275279
async def _post(
276280
self,
@@ -359,7 +363,8 @@ async def _delete(
359363
require_auth: bool = True,
360364
) -> Union[Dict[str, Any], List[Dict[str, Any]], T]:
361365
"""Make a DELETE request."""
362-
return await self.request("DELETE", path, params=params, headers=headers, response_model=response_model, require_auth=require_auth)
366+
return await self.request("DELETE", path, params=params, headers=headers, response_model=response_model,
367+
require_auth=require_auth)
363368

364369
def _delete_sync(
365370
self,
@@ -370,4 +375,5 @@ def _delete_sync(
370375
require_auth: bool = True,
371376
) -> Union[Dict[str, Any], List[Dict[str, Any]], T]:
372377
"""Make a synchronous DELETE request."""
373-
return self.request_sync("DELETE", path, params=params, headers=headers, response_model=response_model, require_auth=require_auth)
378+
return self.request_sync("DELETE", path, params=params, headers=headers, response_model=response_model,
379+
require_auth=require_auth)

src/basalam_sdk/search/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def search_products(self, request: ProductSearchModel) -> Dict[str, Any]:
3535
The search results.
3636
"""
3737
endpoint = "/ai-engine/api/v2.0/product/search"
38-
response = await self._post(endpoint, json_data=request.model_dump(), require_auth=False)
38+
response = await self._post(endpoint, json_data=request.model_dump(exclude_none=True), require_auth=False)
3939
return response
4040

4141
def search_products_sync(self, request: ProductSearchModel) -> Dict[str, Any]:
@@ -49,5 +49,5 @@ def search_products_sync(self, request: ProductSearchModel) -> Dict[str, Any]:
4949
The search results.
5050
"""
5151
endpoint = "/ai-engine/api/v2.0/product/search"
52-
response = self._post_sync(endpoint, json_data=request.model_dump(), require_auth=False)
52+
response = self._post_sync(endpoint, json_data=request.model_dump(exclude_none=True), require_auth=False)
5353
return response

src/basalam_sdk/search/models.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ class HTTPValidationError(BaseModel):
2020

2121
class FiltersModel(BaseModel):
2222
"""Filters model for product search."""
23-
freeShipping: Optional[int] = 0
24-
slug: Optional[str] = "men-shirts"
25-
vendorIdentifier: Optional[str] = "maskbehrokh"
26-
maxPrice: Optional[int] = 100000
27-
minPrice: Optional[int] = 0
28-
sameCity: Optional[int] = 0
29-
minRating: Optional[int] = 4
30-
vendorScore: Optional[int] = 0
23+
freeShipping: Optional[int] = None
24+
slug: Optional[str] = None
25+
vendorIdentifier: Optional[str] = None
26+
maxPrice: Optional[int] = None
27+
minPrice: Optional[int] = None
28+
sameCity: Optional[int] = None
29+
minRating: Optional[int] = None
30+
vendorScore: Optional[int] = None
3131

3232

3333
class ProductSearchModel(BaseModel):
3434
"""Product search request model."""
3535
filters: Optional[FiltersModel] = None
36-
q: Optional[str] = "عسل"
37-
rows: Optional[int] = 12
38-
start: Optional[int] = 0
36+
q: Optional[str] = None
37+
rows: Optional[int] = None
38+
start: Optional[int] = None

0 commit comments

Comments
 (0)