Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def delete_chat_thread(

def close(self):
# type: () -> None
"""Close the ChatClient."""
self._client.close()

def __enter__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ def remove_participant(

def close(self):
# type: () -> None
"""Close the ChatThreadClient."""
return self._client.close()

def __enter__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def _send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs:
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore

def close(self) -> None:
"""Close the client."""
self._client.close()

def __enter__(self) -> "AzureCommunicationChatService":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def _send_request(
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore

async def close(self) -> None:
"""Close the client."""
await self._client.close()

async def __aenter__(self) -> "AzureCommunicationChatService":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable=too-many-lines,too-many-statements
# pylint: disable=too-many-lines,too-many-statements,missing-function-docstring
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
Expand All @@ -10,7 +10,6 @@
from io import IOBase
from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload
import urllib.parse
import uuid

from azure.core.exceptions import (
ClientAuthenticationError,
Expand Down Expand Up @@ -39,6 +38,7 @@


def build_create_chat_thread_request(*, repeatability_request_id: Optional[str] = None, **kwargs: Any) -> HttpRequest:
"""Build HTTP request for creating a chat thread."""
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

Expand Down Expand Up @@ -67,6 +67,7 @@ def build_create_chat_thread_request(*, repeatability_request_id: Optional[str]
def build_list_chat_threads_request(
*, max_page_size: Optional[int] = None, start_time: Optional[datetime.datetime] = None, **kwargs: Any
) -> HttpRequest:
"""Build HTTP request for listing chat threads."""
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

Expand All @@ -90,6 +91,7 @@ def build_list_chat_threads_request(


def build_delete_chat_thread_request(chat_thread_id: str, **kwargs: Any) -> HttpRequest:
"""Build HTTP request for deleting a chat thread."""
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable=too-many-lines,too-many-statements
# pylint: disable=too-many-lines,too-many-statements,missing-function-docstring
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
Expand Down Expand Up @@ -40,6 +40,7 @@
def build_list_chat_read_receipts_request(
chat_thread_id: str, *, max_page_size: Optional[int] = None, skip: Optional[int] = None, **kwargs: Any
) -> HttpRequest:
"""Build HTTP request for listing chat read receipts."""
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

Expand Down Expand Up @@ -68,6 +69,7 @@ def build_list_chat_read_receipts_request(


def build_send_chat_read_receipt_request(chat_thread_id: str, **kwargs: Any) -> HttpRequest:
"""Build HTTP request for sending a chat read receipt."""
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

Expand Down Expand Up @@ -95,6 +97,7 @@ def build_send_chat_read_receipt_request(chat_thread_id: str, **kwargs: Any) ->


def build_send_chat_message_request(chat_thread_id: str, **kwargs: Any) -> HttpRequest:
"""Build HTTP request for sending a chat message."""
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

Expand Down Expand Up @@ -128,6 +131,7 @@ def build_list_chat_messages_request(
start_time: Optional[datetime.datetime] = None,
**kwargs: Any
) -> HttpRequest:
"""Build HTTP request for listing chat messages."""
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ def _sign_request(self, request):
return request

def on_request(self, request):
"""Called to sign the request."""
self._sign_request(request)
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def __exit__(self, *args):
self.close()

def close(self) -> None:
"""Close the credential and cancel any pending refreshes."""
if self._timer is not None:
self._timer.cancel()
self._timer = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ async def __aexit__(self, *args):
await self.close()

async def close(self) -> None:
"""Close the credential and cancel any pending refreshes."""
if self._timer is not None:
self._timer.cancel()
self._timer = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def _convert_datetime_to_utc_int(input_datetime) -> int:


def parse_connection_str(conn_str: Optional[str]) -> Tuple[str, str]:
"""Parse connection string into endpoint and access key."""
if conn_str is None:
raise ValueError("Connection string is undefined.")
endpoint = None
Expand All @@ -51,10 +52,12 @@ def parse_connection_str(conn_str: Optional[str]) -> Tuple[str, str]:


def get_current_utc_time() -> str:
"""Get current UTC time as formatted string."""
return str(datetime.now(tz=TZ_UTC).strftime("%a, %d %b %Y %H:%M:%S ")) + "GMT"


def get_current_utc_as_int() -> int:
"""Get current UTC time as integer."""
current_utc_datetime = datetime.utcnow()
return _convert_datetime_to_utc_int(current_utc_datetime)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ def __init__(self, interval, callback):
self._task = None

def start(self):
"""Start the timer."""
self._task = ensure_future(self._job())

async def _job(self):
await sleep(self._interval)
await self._callback()

def cancel(self):
"""Cancel the timer."""
if self._task is not None:
self._task.cancel()
self._task = None
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def _to_utc_datetime(value):


def return_response(response, deserialized, _): # pylint: disable=unused-argument
"""Return response tuple."""
return response, deserialized


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ async def delete_chat_thread(self, thread_id: str, **kwargs) -> None:
return await self._client.chat.delete_chat_thread(thread_id, **kwargs)

async def close(self) -> None:
"""Close the ChatClient."""
await self._client.close()

async def __aenter__(self) -> "ChatClient":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ async def remove_participant(self, identifier: CommunicationIdentifier, **kwargs
)

async def close(self) -> None:
"""Close the ChatThreadClient."""
await self._client.close()

async def __aenter__(self) -> "ChatThreadClient":
Expand Down
Loading