- Создана структура marketplaces/ для маркетплейсов - Модели: MarketplaceIntegration, WooCommerceIntegration, RecommerceIntegration - Сервисы: MarketplaceService, WooCommerceService, RecommerceService - RecommerceService содержит методы для работы с API: - test_connection(), sync(), fetch_products() - push_product(), update_stock(), update_price() - IntegrationConfig обновлён с новой интеграцией Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
from typing import Tuple
|
||
import requests
|
||
from ..base import BaseIntegrationService
|
||
|
||
|
||
class MarketplaceService(BaseIntegrationService):
|
||
"""
|
||
Базовый сервис для маркетплейсов.
|
||
Содержит общие методы для работы с API маркетплейсов.
|
||
"""
|
||
|
||
def _get_headers(self) -> dict:
|
||
"""Получить заголовки для API запросов"""
|
||
return {
|
||
'Content-Type': 'application/json',
|
||
'User-Agent': 'MyProject/1.0',
|
||
}
|
||
|
||
def _make_request(self, url: str, method: str = 'GET', **kwargs) -> Tuple[bool, dict, str]:
|
||
"""
|
||
Сделать HTTP запрос к API.
|
||
|
||
Returns:
|
||
tuple: (success, response_data, error_message)
|
||
"""
|
||
try:
|
||
response = requests.request(method, url, headers=self._get_headers(), timeout=30, **kwargs)
|
||
|
||
if response.status_code in [200, 201]:
|
||
return True, response.json(), ''
|
||
else:
|
||
error_msg = f"HTTP {response.status_code}: {response.text}"
|
||
return False, {}, error_msg
|
||
|
||
except requests.exceptions.Timeout:
|
||
return False, {}, 'Таймаут соединения'
|
||
except requests.exceptions.ConnectionError:
|
||
return False, {}, 'Ошибка соединения'
|
||
except Exception as e:
|
||
return False, {}, str(e)
|