feat: add platform registry with get_client() dispatch

This commit is contained in:
pyr0ball 2026-04-27 08:12:47 -07:00
parent 38d212726e
commit de6dc645f6
2 changed files with 45 additions and 0 deletions

View file

@ -0,0 +1,28 @@
from __future__ import annotations
from app.services.platforms.base import PostingStrategy, PostResult
from app.services.platforms.reddit_post import RedditPostStrategy
_REGISTRY: dict[str, PostingStrategy] = {
s.campaign_type: s()
for s in [
RedditPostStrategy,
# RedditCommentStrategy — added in Plan B
# BlogPostStrategy — added in Plan C
]
}
SUPPORTED_PLATFORMS: frozenset[str] = frozenset(_REGISTRY)
def get_client(campaign_type: str) -> PostingStrategy:
"""Return the strategy instance for the given campaign type.
Raises ValueError for unknown types.
"""
if campaign_type not in _REGISTRY:
raise ValueError(f"Unknown campaign type: {campaign_type!r}")
return _REGISTRY[campaign_type]
__all__ = ["get_client", "SUPPORTED_PLATFORMS", "PostingStrategy", "PostResult"]

View file

@ -0,0 +1,17 @@
import pytest
from app.services.platforms import get_client, SUPPORTED_PLATFORMS
from app.services.platforms.reddit_post import RedditPostStrategy
def test_get_client_returns_reddit_post_strategy():
client = get_client("reddit_post")
assert isinstance(client, RedditPostStrategy)
def test_get_client_unknown_type_raises():
with pytest.raises(ValueError, match="Unknown campaign type"):
get_client("nonexistent_type")
def test_supported_platforms_contains_reddit_post():
assert "reddit_post" in SUPPORTED_PLATFORMS