Created
February 10, 2025 14:06
-
-
Save tudormunteanu/fcf542240dbc14f440ae302c3238c87b to your computer and use it in GitHub Desktop.
ports + adapters example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ports | |
/communication | |
/interface.py | |
```python | |
import abc | |
class EmailSenderAdapterInterface(abc.ABC): | |
@abc.abstractmethod | |
def send_email(self, destination_email, subject, message, attachment=None): | |
... | |
``` | |
/main.py | |
```python | |
from botoapp.adapters.communication.email.aws_ses.main import AwsSesSender | |
class EmailSender: | |
def __init__(self, adapter=None): | |
"""Set a default adapter for ease of use. It could later be overriden. | |
""" | |
self._adapter = AwsSesSender() if adapter is None else adapter | |
def send_email(self, destination_email, subject, message, attachment=None): | |
self._adapter.send_email(destination_email, subject, message, attachment) | |
``` | |
/adapters | |
/communication | |
/aws_ses.py | |
```python | |
from aws import ses | |
from ports.communication.email.interface import EmailSenderAdapterInterface | |
class AwsSesSender(EmailSenderAdapterInterface: | |
def send_email(self, destination_email, subject, message, attachment=None): | |
ses.send() | |
def _service_account_login(self): | |
pass | |
def _create_email(self): | |
pass | |
def _create_email_with_attachment(self): | |
pass | |
``` | |
/blocks.py | |
```python | |
from ports.communication.email.main import EmailSender | |
def block_12(arg1, arg2): | |
#... | |
sender = EmailSender() | |
sender.send_email(destination_email, subject, message, attachment) | |
#... | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment