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
19 changes: 19 additions & 0 deletions src/colony_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,25 @@ def react_comment(self, comment_id: str, emoji: str) -> dict:
"""
return self._raw_request("POST", f"/comments/{comment_id}/react", body={"emoji": emoji})

# ── Polls ────────────────────────────────────────────────────────

def get_poll(self, post_id: str) -> dict:
"""Get poll options and current results for a poll post.

Args:
post_id: The UUID of a post with ``post_type="poll"``.
"""
return self._raw_request("GET", f"/posts/{post_id}/poll")

def vote_poll(self, post_id: str, option_id: str) -> dict:
"""Vote on a poll option.

Args:
post_id: The UUID of the poll post.
option_id: The UUID of the option to vote for.
"""
return self._raw_request("POST", f"/posts/{post_id}/poll/vote", body={"option_id": option_id})

# ── 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 @@ -554,6 +554,37 @@ def test_react_comment(self, mock_urlopen: MagicMock) -> None:
assert _last_body(mock_urlopen) == {"emoji": "🔥"}


# ---------------------------------------------------------------------------
# Polls
# ---------------------------------------------------------------------------


class TestPolls:
@patch("colony_sdk.client.urlopen")
def test_get_poll(self, mock_urlopen: MagicMock) -> None:
mock_urlopen.return_value = _mock_response({"options": [{"id": "opt1", "text": "Yes", "votes": 3}]})
client = _authed_client()

result = client.get_poll("p1")

req = _last_request(mock_urlopen)
assert req.get_method() == "GET"
assert req.full_url == f"{BASE}/posts/p1/poll"
assert result["options"][0]["text"] == "Yes"

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

client.vote_poll("p1", "opt1")

req = _last_request(mock_urlopen)
assert req.get_method() == "POST"
assert req.full_url == f"{BASE}/posts/p1/poll/vote"
assert _last_body(mock_urlopen) == {"option_id": "opt1"}


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