Spaces:
Sleeping
Sleeping
Create adapters.py
Browse files- app/adapters.py +24 -0
app/adapters.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
from typing import Dict, Any
|
| 3 |
+
from . import storage
|
| 4 |
+
|
| 5 |
+
class BaseAdapter:
|
| 6 |
+
name = "base"
|
| 7 |
+
|
| 8 |
+
def __init__(self, campaign_id: str):
|
| 9 |
+
self.campaign_id = campaign_id
|
| 10 |
+
|
| 11 |
+
def send(self, variant_id: str, text: str, context: Dict[str, Any]) -> Dict[str, Any]:
|
| 12 |
+
# 実配信の代わりに監査ログへ記録。実装時はAPI呼び出しに差し替え。
|
| 13 |
+
payload = {"adapter": self.name, "variant_id": variant_id, "text": text, "context": context}
|
| 14 |
+
storage.audit(self.campaign_id, f"adapter_send:{self.name}", payload)
|
| 15 |
+
return {"ok": True, "note": f"stubbed send via {self.name}"}
|
| 16 |
+
|
| 17 |
+
class XAdapter(BaseAdapter):
|
| 18 |
+
name = "x"
|
| 19 |
+
|
| 20 |
+
class MetaAdapter(BaseAdapter):
|
| 21 |
+
name = "meta"
|
| 22 |
+
|
| 23 |
+
class GoogleAdsAdapter(BaseAdapter):
|
| 24 |
+
name = "google"
|