feat(integrations): добавлена заготовка интеграции Recommerce
- Создана структура 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>
This commit is contained in:
40
myproject/integrations/services/marketplaces/base.py
Normal file
40
myproject/integrations/services/marketplaces/base.py
Normal file
@@ -0,0 +1,40 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user