From 369276a32084bea767866f30c18fbea19c6b45cf Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 8 Oct 2020 22:31:55 +0200 Subject: [PATCH] Subscribe and unsubscribe --- sympasoap/client.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/sympasoap/client.py b/sympasoap/client.py index b3d3cf2..1224913 100644 --- a/sympasoap/client.py +++ b/sympasoap/client.py @@ -165,3 +165,34 @@ class Client: f"Maybe the list did not exist?", e) else: return False + + def subscribe(self, email: str, list_address: str, quiet: bool, name: str = "", raise_error: bool = False) -> bool: + """ + Subscribe the user with the given email to the given mailing list. + If the quiet mode is enabled, the user won't receive a notification that they got subscribed. + """ + try: + result = self.zeep.service.add(list_address, email, name, quiet) + return result._raw_elements[0].text == "true" + except Fault as e: + if raise_error: + raise Fault(f"An unknown error occured while subscribing to the list {list_address}. " + f"Maybe the user is already a member?", e) + else: + return False + + def unsubscribe(self, email: str, list_address: str, quiet: bool, raise_error: bool = False) -> bool: + """ + Subscribe the user with the given email to the given mailing list. + If the quiet mode is enabled, the user won't receive a notification that they got subscribed. + """ + try: + # del is a reserved keyword + result = getattr(self.zeep.service, "del")(list_address, email, quiet) + return result._raw_elements[0].text == "true" + except Fault as e: + if raise_error: + raise Fault(f"An unknown error occured while subscribing to the list {list_address}. " + f"Maybe the user is already a member?", e) + else: + return False