Skip to content

Add missing method: delete_channel #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 26, 2024
Merged
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
11 changes: 10 additions & 1 deletion swibots/api/community/controllers/channel_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) -> bool:
response = await self.client.delete(f"{BASE_PATH}/{channel_id}")
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())
return response.data.get("result", {}).get("channelId")
Expand Down
16 changes: 16 additions & 0 deletions swibots/api/community/methods/channel_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> bool:
"""Delete channel

Args:
:obj:`swibots.api.community.models.Channel`: The channel object.

Returns:
bool: Whether the channel was deleted!

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]:
Expand Down
Loading