Skip to content

Commit

Permalink
chore: additional testing, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Teqed committed Aug 8, 2023
1 parent 25c3427 commit 6fceee6
Show file tree
Hide file tree
Showing 5 changed files with 873 additions and 695 deletions.
5 changes: 3 additions & 2 deletions fedifetcher/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""__init__.py for api."""

from . import api
from .api import API, FederationInterface
from .firefish import api_firefish, api_firefish_types
from .lemmy import api_lemmy
from .mastodon import api_mastodon, api_mastodon_types
from .postgresql import postgresql

__all__ = [
"api",
"API",
"FederationInterface",
"api_firefish",
"api_firefish_types",
"api_lemmy",
Expand Down
26 changes: 26 additions & 0 deletions fedifetcher/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,29 @@ def get_ids_from_list(self, uris: list[str]) -> Coroutine[Any, Any, dict[str, st
def get_context(self, uri: str) -> Coroutine[Any, Any, list[str]]:
"""Get the context of an object by URI."""
raise NotImplementedError

class FederationInterface:
"""Interface for dependency injection of different federation APIs."""

_equipped_api: API

def __init__(self, equippable_api: API) -> None:
"""Initialize the API."""
self._equipped_api: API = equippable_api

def get(self, uri: str) -> Coroutine[Any, Any, dict | bool]:
"""Get an object by URI."""
return self._equipped_api.get(uri)

def get_id(self, uri: str) -> Coroutine[Any, Any, str | None]:
"""Get the ID of an object by URI."""
return self._equipped_api.get_id(uri)

def get_ids_from_list(self, uris: list[str]) -> Coroutine[Any, Any, dict[str, str]]:
"""Get the IDs of objects by URIs."""
return self._equipped_api.get_ids_from_list(uris)

def get_context(self, uri: str) -> Coroutine[Any, Any, list[str]]:
"""Get the context of an object by URI."""
return self._equipped_api.get_context(uri)

Loading

0 comments on commit 6fceee6

Please sign in to comment.