46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
from typing import Dict, Any, Optional
|
|
from ..client import YMClient
|
|
|
|
class OrdersService:
|
|
"""Service to handle Yandex Market Orders."""
|
|
|
|
def __init__(self, client: YMClient):
|
|
self.client = client
|
|
|
|
def get_list(self, campaign_id: Optional[str] = None, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
"""
|
|
Get list of orders for a specific campaign.
|
|
Endpoint: /campaigns/{campaignId}/orders.json
|
|
"""
|
|
cid = campaign_id or self.client.campaign_id
|
|
if not cid:
|
|
raise ValueError("campaign_id must be provided either in the method call or client initialization.")
|
|
|
|
return self.client.get(f"/campaigns/{cid}/orders.json", params=params)
|
|
|
|
def get_order(self, order_id: str, campaign_id: Optional[str] = None) -> Dict[str, Any]:
|
|
"""
|
|
Get info about a specific order.
|
|
Endpoint: /campaigns/{campaignId}/orders/{orderId}.json
|
|
"""
|
|
cid = campaign_id or self.client.campaign_id
|
|
if not cid:
|
|
raise ValueError("campaign_id must be provided either in the method call or client initialization.")
|
|
|
|
return self.client.get(f"/campaigns/{cid}/orders/{order_id}.json")
|
|
|
|
def update_status(self, order_id: str, status: str, substatus: Optional[str] = None, campaign_id: Optional[str] = None) -> Dict[str, Any]:
|
|
"""
|
|
Update the status of an order.
|
|
Endpoint: /campaigns/{campaignId}/orders/{orderId}/status.json
|
|
"""
|
|
cid = campaign_id or self.client.campaign_id
|
|
if not cid:
|
|
raise ValueError("campaign_id must be provided either in the method call or client initialization.")
|
|
|
|
payload = {"order": {"status": status}}
|
|
if substatus:
|
|
payload["order"]["substatus"] = substatus
|
|
|
|
return self.client.put(f"/campaigns/{cid}/orders/{order_id}/status.json", data=payload)
|