feat: add PostingStrategy ABC and PostResult dataclass

This commit is contained in:
pyr0ball 2026-04-27 08:00:36 -07:00
parent e158787b59
commit 2dd88285a2
6 changed files with 49 additions and 0 deletions

View file

View file

@ -0,0 +1,37 @@
from __future__ import annotations
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
@dataclass
class PostResult:
url: str
metadata: dict | None = field(default=None)
class PostingStrategy(ABC):
"""Base class for all posting output types.
Subclasses must set class attribute `campaign_type` matching the value
stored in campaigns.type.
"""
campaign_type: str # e.g. "reddit_post", "reddit_comment", "blog_post"
@abstractmethod
def execute(
self,
*,
target: str,
title: str,
body: str,
flair: str | None = None,
extra: dict | None = None,
) -> PostResult:
"""Execute the post. Raise on failure. Return PostResult on success."""
...
def supports_dupe_guard(self) -> bool:
"""Return False to skip the weekly-dupe-guard check for this type."""
return True

0
tests/__init__.py Normal file
View file

View file

View file

View file

@ -0,0 +1,12 @@
from app.services.platforms.base import PostResult
def test_post_result_requires_url():
r = PostResult(url="https://reddit.com/r/test/comments/abc")
assert r.url == "https://reddit.com/r/test/comments/abc"
assert r.metadata is None
def test_post_result_accepts_metadata():
r = PostResult(url="https://example.com", metadata={"id": "abc123"})
assert r.metadata == {"id": "abc123"}