from dataclasses import dataclass from owsclient import OwsClient from app.types import EmailType @dataclass class OwsPreferenceCenterClient: ows_client: OwsClient ows_client_timeout: int service_name = "ows-preference-center" def unsubscribe( self, email: str, email_type: str | None = None, email_id: str | None = None, automated_email_trigger_id: str | None = None, ) -> None: """ Unsubscribe user """ if email_type == EmailType.AUTOMATED: origin_type = "AUTOMATED_EMAIL" else: origin_type = "EMAIL_CAMPAIGN" data = { "email": email, "originType": origin_type, "originId": email_id, "automatedEmailTriggerId": automated_email_trigger_id, } response = self.ows_client.post( self.service_name, "/subscriptions/unsubscribe-all", json=data, timeout=self.ows_client_timeout, ) response.raise_for_status()