Subscribe and unsubscribe

This commit is contained in:
Yohann D'ANELLO 2020-10-08 22:31:55 +02:00
parent e1faf7b4b2
commit 369276a320
1 changed files with 31 additions and 0 deletions

View File

@ -165,3 +165,34 @@ class Client:
f"Maybe the list did not exist?", e) f"Maybe the list did not exist?", e)
else: else:
return False 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