diff --git a/sinch/core/adapters/asyncio_http_adapter.py b/sinch/core/adapters/asyncio_http_adapter.py index 7c12d151..a34d6613 100644 --- a/sinch/core/adapters/asyncio_http_adapter.py +++ b/sinch/core/adapters/asyncio_http_adapter.py @@ -3,10 +3,11 @@ from sinch.core.ports.http_transport import AsyncHTTPTransport, HttpRequest from sinch.core.endpoint import HTTPEndpoint from sinch.core.models.http_response import HTTPResponse +from sinch.core.models.base_model import SinchBaseModel class HTTPTransportAioHTTP(AsyncHTTPTransport): - async def request(self, endpoint: HTTPEndpoint) -> HTTPResponse: + async def request(self, endpoint: HTTPEndpoint) -> SinchBaseModel: request_data: HttpRequest = self.prepare_request(endpoint) request_data_with_auth: HttpRequest = await self.authenticate(endpoint, request_data) diff --git a/sinch/core/ports/http_transport.py b/sinch/core/ports/http_transport.py index 27be9fc2..a3358675 100644 --- a/sinch/core/ports/http_transport.py +++ b/sinch/core/ports/http_transport.py @@ -1,6 +1,6 @@ import aiohttp from abc import ABC, abstractmethod -from typing import TYPE_CHECKING +from typing import Optional, TYPE_CHECKING, Union, Any, Coroutine from sinch.core.endpoint import HTTPEndpoint from sinch.core.models.http_request import HttpRequest from sinch.core.models.http_response import HTTPResponse @@ -17,7 +17,7 @@ def __init__(self, sinch: 'ClientBase'): self.sinch = sinch @abstractmethod - def request(self, endpoint: HTTPEndpoint) -> SinchBaseModel: + def request(self, endpoint: HTTPEndpoint) -> Union[SinchBaseModel, Coroutine[Any, Any, SinchBaseModel]]: pass def authenticate(self, endpoint: HTTPEndpoint, request_data: HttpRequest) -> HttpRequest: @@ -74,7 +74,7 @@ async def authenticate(self, endpoint: HTTPEndpoint, request_data: HttpRequest) return request_data - async def handle_response(self, endpoint: HTTPEndpoint, http_response: HTTPResponse) -> HTTPResponse: + async def handle_response(self, endpoint: HTTPEndpoint, http_response: HTTPResponse) -> SinchBaseModel: if http_response.status_code == 401: self.sinch.configuration.token_manager.handle_invalid_token(http_response) if self.sinch.configuration.token_manager.token_state == TokenState.EXPIRED: diff --git a/sinch/core/token_manager.py b/sinch/core/token_manager.py index df28b56c..4cbc7098 100644 --- a/sinch/core/token_manager.py +++ b/sinch/core/token_manager.py @@ -1,6 +1,6 @@ from enum import Enum from abc import ABC, abstractmethod -from typing import Optional, TYPE_CHECKING, Union, Any +from typing import Optional, TYPE_CHECKING, Union, Any, Coroutine from sinch.domains.authentication.models.authentication import OAuthToken from sinch.domains.authentication.endpoints.oauth import OAuthEndpoint @@ -24,7 +24,7 @@ def __init__(self, sinch: 'ClientBase') -> None: self.token_state = TokenState.INVALID @abstractmethod - def get_auth_token(self) -> Optional[OAuthToken]: + def get_auth_token(self) -> Union[Optional[OAuthToken], Coroutine[Any, Any, Optional[OAuthToken]]]: pass def invalidate_expired_token(self) -> None: