Skip to content

Commit

Permalink
Refactor the obsolete teams client class
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Tubbing committed Feb 7, 2024
1 parent 5855f81 commit 111e381
Showing 1 changed file with 18 additions and 37 deletions.
55 changes: 18 additions & 37 deletions elementary/clients/teams/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
class TeamsClient(ABC):
def __init__(
self,
webhook: str,
tracking: Optional[Tracking] = None,
):
self.client = self._initial_client()
self.webhook = webhook
self.tracking = tracking
self.client = self._initial_client()

@staticmethod
def create_client(
Expand All @@ -33,16 +35,23 @@ def create_client(
)
return None

@abstractmethod
def _initial_client(self):
raise NotImplementedError
return connectorcard(self.webhook)

def _initial_retry_handlers(self):
raise NotImplementedError
@retry(tries=3, delay=1, backoff=2, max_delay=5)
def send_message(self, **kwargs) -> bool:
self.client.send()
response = self.client.last_http_response

@abstractmethod
def send_message(self, **kwargs):
raise NotImplementedError
if response.status_code == OK_STATUS_CODE:
return True
else:
logger.error(
"Could not post message to teams via webhook - %s. Error: %s",
{self.webhook},
{response.body},
)
return False

@abstractmethod
def title(self, title: str):
Expand All @@ -61,35 +70,7 @@ def addPotentialAction(self, action: potentialaction):
raise NotImplementedError


class TeamsWebhookClient(TeamsClient):
def __init__(
self,
webhook: str,
tracking: Optional[Tracking] = None,
):
self.webhook = webhook
super().__init__(tracking)

def _initial_client(self):
return connectorcard(self.webhook)

@retry(tries=3, delay=1, backoff=2, max_delay=5)
def send_message(self, **kwargs) -> bool:
self.client.send()
response = self.client.last_http_response

if response.status_code == OK_STATUS_CODE:
return True
else:
logger.error(
"Could not post message to teams via webhook - %s. Error: %s",
{self.webhook},
{response.body},
)
return False


class TeamsWebhookMessageBuilderClient(TeamsWebhookClient):
class TeamsWebhookMessageBuilderClient(TeamsClient):
def __init__(
self,
webhook: str,
Expand Down

0 comments on commit 111e381

Please sign in to comment.