From 22d890bb0e74ea85c5beca07b251f377031feda7 Mon Sep 17 00:00:00 2001 From: buddhhu Date: Sun, 26 May 2024 12:29:02 +0530 Subject: [PATCH 1/3] Add missing method: `delete_channel` --- .../community/controllers/channel_controller.py | 9 +++++++++ swibots/api/community/methods/channel_methods.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/swibots/api/community/controllers/channel_controller.py b/swibots/api/community/controllers/channel_controller.py index f845db0d..c8547686 100644 --- a/swibots/api/community/controllers/channel_controller.py +++ b/swibots/api/community/controllers/channel_controller.py @@ -25,6 +25,15 @@ async def create_channel(self, channel: Channel) -> str: response = await self.client.post(BASE_PATH, data=channel.to_json_request()) return response.data.get("result", {}).get("channelId") + async def delete_channel(self, channel_id: str) -> str: + response = await self.client.delete(f"{BASE_PATH}/{channel_id}") + # return response.data.get("result", {}).get("channelId") + return ( + "Successfully deleted the channel." + if response.status_code == 200 + else response.data.get("errorMessage") + ) + async def update_channel(self, channel: Channel) -> str: response = await self.client.put(BASE_PATH, data=channel.to_json_request()) return response.data.get("result", {}).get("channelId") diff --git a/swibots/api/community/methods/channel_methods.py b/swibots/api/community/methods/channel_methods.py index 3729d237..8e9aa7fb 100644 --- a/swibots/api/community/methods/channel_methods.py +++ b/swibots/api/community/methods/channel_methods.py @@ -37,6 +37,22 @@ async def update_channel(self: "swibots.ApiClient", channel: Channel) -> str: """ return await self.community_service.channels.update_channel(channel) + async def delete_channel(self: "swibots.ApiClient", id: str) -> str: + """Delete channel + + Args: + :obj:`swibots.api.community.models.Channel`: The channel object. + + Returns: + str: status of channel + + Raises: + :obj:`switch.error.SwitchError`: If the channel could not be retrieved + + This method does the same as :meth:`switch.api.community.controllers.ChannelController.delete_channel`. + """ + return await self.community_service.channels.delete_channel(id) + async def get_all_channels( self: "swibots.ApiClient", community_id: str ) -> List[Channel]: From 6f4593464ab60fb6b54474a1d1600a306e5aee9c Mon Sep 17 00:00:00 2001 From: Devesh Pal Date: Sun, 26 May 2024 15:30:26 +0530 Subject: [PATCH 2/3] Update channel_controller.py --- .../community/controllers/channel_controller.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/swibots/api/community/controllers/channel_controller.py b/swibots/api/community/controllers/channel_controller.py index c8547686..f39a78d6 100644 --- a/swibots/api/community/controllers/channel_controller.py +++ b/swibots/api/community/controllers/channel_controller.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING, List from swibots.api.community.models import Channel - +from swibots.errors import SwitchError if TYPE_CHECKING: from swibots.api.community import CommunityClient @@ -25,14 +25,14 @@ async def create_channel(self, channel: Channel) -> str: response = await self.client.post(BASE_PATH, data=channel.to_json_request()) return response.data.get("result", {}).get("channelId") - async def delete_channel(self, channel_id: str) -> str: + async def delete_channel(self, channel_id: str) -> bool: response = await self.client.delete(f"{BASE_PATH}/{channel_id}") - # return response.data.get("result", {}).get("channelId") - return ( - "Successfully deleted the channel." - if response.status_code == 200 - else response.data.get("errorMessage") - ) + if response.status_code == 200: + return True + logging.debug(response.data) + if err:= response.data.get("errorMessage"): + raise SwitchError(err) + return False async def update_channel(self, channel: Channel) -> str: response = await self.client.put(BASE_PATH, data=channel.to_json_request()) From f6afa9011e3594a24c291f1683709f7a33f0c4d0 Mon Sep 17 00:00:00 2001 From: Devesh Pal Date: Sun, 26 May 2024 15:31:14 +0530 Subject: [PATCH 3/3] Update channel_methods.py --- swibots/api/community/methods/channel_methods.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swibots/api/community/methods/channel_methods.py b/swibots/api/community/methods/channel_methods.py index 8e9aa7fb..15ef887a 100644 --- a/swibots/api/community/methods/channel_methods.py +++ b/swibots/api/community/methods/channel_methods.py @@ -37,14 +37,14 @@ async def update_channel(self: "swibots.ApiClient", channel: Channel) -> str: """ return await self.community_service.channels.update_channel(channel) - async def delete_channel(self: "swibots.ApiClient", id: str) -> str: + async def delete_channel(self: "swibots.ApiClient", id: str) -> bool: """Delete channel Args: :obj:`swibots.api.community.models.Channel`: The channel object. Returns: - str: status of channel + bool: Whether the channel was deleted! Raises: :obj:`switch.error.SwitchError`: If the channel could not be retrieved