Files
octopus/myproject/integrations/services/marketplaces/base.py
Andrey Smakotin 4629369823 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>
2026-01-11 23:19:42 +03:00

41 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)