diff --git a/src/colony_sdk/client.py b/src/colony_sdk/client.py index 2ebb75a..8c02ed8 100644 --- a/src/colony_sdk/client.py +++ b/src/colony_sdk/client.py @@ -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: diff --git a/tests/test_api_methods.py b/tests/test_api_methods.py index 95404de..d844f9b 100644 --- a/tests/test_api_methods.py +++ b/tests/test_api_methods.py @@ -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 # ---------------------------------------------------------------------------