feat: add list_messages method for reading group message history #4
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "3-add-list-messages"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds
list_messages()toMessagesMixin, enabling reading group message history via the GroupMe messages index endpoint. Supports pagination throughbefore_id,since_id, andafter_idparameters, with a default limit of 20 clamped to the API maximum of 100. No automatic pagination -- API parameters are exposed directly.Changes
src/groupme_sdk/messages.py: Addedlist_messages(group_id, before_id=None, since_id=None, after_id=None, limit=20)method that callsGET /groups/{group_id}/messagesand extracts themessageslist from the response envelopetests/test_messages.py: Added 9 unit tests inTestListMessagesclass covering: list return with full message data (text, sender name, created_at, attachments), all three pagination parameters, empty group response, default limit, limit clamping to 100, custom limit, and 404 error handlingTest Plan
pytest tests/ -v -m "not integration"-- 36 passed, 0 failedruff check src/ tests/-- all checks passedruff format --check src/ tests/-- all files formattedReview Checklist
Related
Review -- LGTM
Files reviewed:
src/groupme_sdk/messages.py,tests/test_messages.py(2 files, +168/-1)Correctness
list_messages(group_id, before_id=None, since_id=None, after_id=None, limit=20)result.get("messages", [])per the implementation note about the API envelopemin(limit, 100)Pattern Consistency
self: GroupMeClienttype annotation matchesgroups.pyandmembers.py_request("GET", ...)consistent with existing read methodsmake_client,mock_response,mock_http_errorfixtures from conftestTest Coverage
Verification
ruff check-- passedruff format --check-- passedpytest tests/ -v -m "not integration"-- 36 passed, 0 failedNo findings. Ready to merge.
PR #4 Review
DOMAIN REVIEW
Tech stack: Pure Python SDK, urllib-based HTTP client, pytest unit tests, ruff linting. Reviewed against Python/PEP standards and SDK design patterns.
Architecture consistency: The new
list_messages()method follows the established mixin pattern (MessagesMixinwithself: GroupMeClienttyping), matches the docstring style of existing methods, and uses the same_request()plumbing. The response envelope extraction (result.get("messages", [])) correctly handles the GroupMe messages endpoint which nests data under amessageskey (unlike most endpoints which useresponse-- the client's_requestalready unwraps that outerresponseenvelope, so.get("messages", [])extracts the inner list). This is correct.Query parameter construction: Parameters are built via manual f-string interpolation and
"&".join(params). This is consistent with the existinglist_groupsingroups.py(line 38), so it follows the established pattern. The pagination IDs (before_id,since_id,after_id) are not URL-encoded viaurllib.parse.quote, but GroupMe message IDs are numeric strings, so injection risk is negligible here.Limit clamping:
min(limit, 100)correctly caps at the API maximum. However, there is no floor --limit=0orlimit=-1would pass through unclamped. The API likely rejects these gracefully, butmax(1, min(limit, 100))would be more defensive.Test coverage: 9 tests in
TestListMessagescovering: full message data assertions, all three pagination parameters (with URL inspection), empty group, default limit, limit clamping to 100, custom limit, and 404 error. This is thorough and well-structured.BLOCKERS
None.
NITS
Negative limit not clamped (
messages.pyline 56):min(limit, 100)does not protect against zero or negative values. Considermax(1, min(limit, 100))for defensive completeness. Low risk since the GroupMe API would reject bad values, but SDK callers would get a confusing API error instead of a clear local one.Imprecise exception assertion (
test_messages.py,test_list_messages_not_found): Usespytest.raises(Exception)rather thanpytest.raises(GroupMeNotFoundError). The existingtest_send_message_to_nonexistent_grouphas the same pattern, so this is consistent but imprecise. A future test improvement could tighten both to assert the specific exception type and status code, similar to howtest_send_message_server_errorassertsGroupMeHTTPErrorwithstatus_code == 500.No test for negative/zero limit behavior: Since the clamping logic only caps at 100, a test for
limit=0orlimit=-1would document the expected behavior (or catch the gap from nit #1).SOP COMPLIANCE
3-add-list-messagesreferences issue #3)Closes #3links to parent issuePROCESS OBSERVATIONS
list_messagesusage example, but that is out of scope for this PR.VERDICT: APPROVED