From d1419f91f4f6cf74ea82c3c2a3943bb74c27bd70 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 8 Oct 2020 18:27:33 +0200 Subject: [PATCH] Check if an email is subscribed in a list. --- sympasoap/client.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sympasoap/client.py b/sympasoap/client.py index 9982ad8..3ea0462 100644 --- a/sympasoap/client.py +++ b/sympasoap/client.py @@ -4,9 +4,9 @@ from zeep.client import Client as ZeepClient, Settings as ZeepSettings class Client: def __init__(self, sympa_url: str): self.sympa_url = sympa_url - self.zeep = ZeepClient(sympa_url + "/wsgl", settings=ZeepSettings(strict=False)) + self.zeep = ZeepClient(sympa_url + "/wsdl", settings=ZeepSettings(strict=False)) - def login(self, email, password): + def login(self, email: str, password: str) -> None: """ Login into the API. Set a cookie for future connexions. """ @@ -19,10 +19,21 @@ class Client: raise Exception("Unknown error: given cookie is invalid") print("Successfully authenticated!") - def checkCookie(self): + def checkCookie(self) -> str: """ From the current cookie, retrieve the email address. """ result = self.zeep.service.checkCookie() element = result._raw_elements[0] return element.text + + def amI(self, mailing_list: str, function: str, email: str) -> bool: + """ + Check if the given `email` is a member of type `function` in the `mailing_list`. + The function parameter is one between subscriber, editor or owner. + """ + if function not in ["subscriber", "editor", "owner"]: + raise ValueError("function of a mailing list member must be subscriber, editor or owner.") + result = self.zeep.service.amI(mailing_list, function, email) + element = result._raw_elements[0] + return element.text == "true"