Files
Touchh/pms_integration/plugins/base_plugin.py
2024-12-27 14:47:04 +09:00

59 lines
1.9 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 abc import ABC, abstractmethod
class BasePMSPlugin(ABC):
"""
Базовый класс для всех PMS плагинов.
Плагин должен уметь:
- Возвращать данные fetch_data()
- Предоставлять дефолтные parser_settings
- Проходить базовую валидацию (validate_plugin)
"""
def __init__(self, pms_config):
"""
pms_config: объект PMSConfiguration
"""
self.pms_config = pms_config
@abstractmethod
async def _fetch_data(self):
"""
Абстрактный метод для получения данных.
"""
pass
async def fetch_data(self):
"""
Обертка для выполнения _fetch_data с возможной дополнительной обработкой.
"""
return await self._fetch_data()
@abstractmethod
def get_default_parser_settings(self):
"""
Возвращает словарь/JSON с дефолтными настройками разбора.
Например:
{
"fields_mapping": {
"reservation_id": "id",
"check_in": "from",
"check_out": "until"
},
"conditions": {
"checkInStatus": "Заселен"
}
}
"""
return {}
def validate_plugin(self):
"""
Проверка на соответствие требованиям.
Можно проверить наличие методов или полей.
"""
required_methods = ["fetch_data", "get_default_parser_settings", "_fetch_data"]
for method in required_methods:
if not hasattr(self, method):
raise ValueError(f"Плагин {type(self).__name__} не реализует метод {method}.")
return True