diff --git a/google_nest_sdm/admin_client.py b/google_nest_sdm/admin_client.py index e5a974a9..c61ca519 100644 --- a/google_nest_sdm/admin_client.py +++ b/google_nest_sdm/admin_client.py @@ -124,12 +124,12 @@ def __init__( async def create_topic(self, topic_name: str) -> None: """Create a pubsub topic for the project.""" validate_topic_name(topic_name) - await self._auth.request("put", topic_name) + await self._auth.put(topic_name) async def delete_topic(self, topic_name: str) -> None: """Delete a pubsub topic for the project.""" validate_topic_name(topic_name) - await self._auth.request("delete", topic_name) + await self._auth.delete(topic_name) async def list_topics(self, projects_prefix: str) -> list[str]: """List the pubsub topics for the project. @@ -152,12 +152,12 @@ async def create_subscription( validate_topic_name(topic_name) validate_subscription_name(subscription_name) body = {"topic": topic_name} - await self._auth.request("put", subscription_name, json=body) + await self._auth.put(subscription_name, json=body) async def delete_subscription(self, subscription_name: str) -> None: """Delete a pubsub subscription for the project.""" validate_subscription_name(subscription_name) - await self._auth.request("delete", subscription_name) + await self._auth.delete(subscription_name) async def list_subscriptions(self, projects_prefix: str) -> list[dict[str, Any]]: """List the pubsub subscriptions for the project. diff --git a/google_nest_sdm/auth.py b/google_nest_sdm/auth.py index 5dc83e65..3947414a 100644 --- a/google_nest_sdm/auth.py +++ b/google_nest_sdm/auth.py @@ -145,13 +145,12 @@ async def request( async def _request( self, method: str, url: str, headers: dict[str, str], **kwargs: Any ) -> aiohttp.ClientResponse: - response = await self._websession.request(method, url, **kwargs, headers=headers) - return await AbstractAuth._raise_for_status(response) - + return await self._websession.request(method, url, **kwargs, headers=headers) async def get(self, url: str, **kwargs: Any) -> aiohttp.ClientResponse: """Make a get request.""" - return await self.request("get", url, **kwargs) + response = await self.request("get", url, **kwargs) + return await AbstractAuth._raise_for_status(response) async def get_json(self, url: str, **kwargs: Any) -> dict[str, Any]: """Make a get request and return json response.""" @@ -167,7 +166,8 @@ async def get_json(self, url: str, **kwargs: Any) -> dict[str, Any]: async def post(self, url: str, **kwargs: Any) -> aiohttp.ClientResponse: """Make a post request.""" - return await self.request("post", url, **kwargs) + response = await self.request("post", url, **kwargs) + return await AbstractAuth._raise_for_status(response) async def post_json(self, url: str, **kwargs: Any) -> dict[str, Any]: """Make a post request and return a json response.""" @@ -181,6 +181,16 @@ async def post_json(self, url: str, **kwargs: Any) -> dict[str, Any]: _LOGGER.debug("response=%s", result) return result + async def put(self, url: str, **kwargs: Any) -> aiohttp.ClientResponse: + """Make a put request.""" + response = await self.request("put", url, **kwargs) + return await AbstractAuth._raise_for_status(response) + + async def delete(self, url: str, **kwargs: Any) -> aiohttp.ClientResponse: + """Make a delete request.""" + response = await self.request("delete", url, **kwargs) + return await AbstractAuth._raise_for_status(response) + @classmethod async def _raise_for_status( cls, resp: aiohttp.ClientResponse diff --git a/setup.cfg b/setup.cfg index 0f197439..980c2f4b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = google_nest_sdm -version = 6.1.2 +version = 6.1.3 description = Library for the Google Nest SDM API long_description = file: README.md long_description_content_type = text/markdown