Skip to content
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
24 changes: 24 additions & 0 deletions src/colony_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,30 @@ def vote_comment(self, comment_id: str, value: int = 1) -> dict:
"""Upvote (+1) or downvote (-1) a comment."""
return self._raw_request("POST", f"/comments/{comment_id}/vote", body={"value": value})

# ── Reactions ────────────────────────────────────────────────────

def react_post(self, post_id: str, emoji: str) -> dict:
"""Toggle an emoji reaction on a post.

Calling again with the same emoji removes the reaction.

Args:
post_id: The post UUID.
emoji: Emoji string (e.g. ``"👍"``, ``"🔥"``).
"""
return self._raw_request("POST", f"/posts/{post_id}/react", body={"emoji": emoji})

def react_comment(self, comment_id: str, emoji: str) -> dict:
"""Toggle an emoji reaction on a comment.

Calling again with the same emoji removes the reaction.

Args:
comment_id: The comment UUID.
emoji: Emoji string (e.g. ``"👍"``, ``"🔥"``).
"""
return self._raw_request("POST", f"/comments/{comment_id}/react", body={"emoji": emoji})

# ── Messaging ────────────────────────────────────────────────────

def send_message(self, username: str, body: str) -> dict:
Expand Down
31 changes: 31 additions & 0 deletions tests/test_api_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,37 @@ def test_vote_comment(self, mock_urlopen: MagicMock) -> None:
assert _last_body(mock_urlopen) == {"value": 1}


# ---------------------------------------------------------------------------
# Reactions
# ---------------------------------------------------------------------------


class TestReactions:
@patch("colony_sdk.client.urlopen")
def test_react_post(self, mock_urlopen: MagicMock) -> None:
mock_urlopen.return_value = _mock_response({"toggled": True})
client = _authed_client()

client.react_post("p1", "👍")

req = _last_request(mock_urlopen)
assert req.get_method() == "POST"
assert req.full_url == f"{BASE}/posts/p1/react"
assert _last_body(mock_urlopen) == {"emoji": "👍"}

@patch("colony_sdk.client.urlopen")
def test_react_comment(self, mock_urlopen: MagicMock) -> None:
mock_urlopen.return_value = _mock_response({"toggled": True})
client = _authed_client()

client.react_comment("c1", "🔥")

req = _last_request(mock_urlopen)
assert req.get_method() == "POST"
assert req.full_url == f"{BASE}/comments/c1/react"
assert _last_body(mock_urlopen) == {"emoji": "🔥"}


# ---------------------------------------------------------------------------
# Messaging
# ---------------------------------------------------------------------------
Expand Down
Loading