Skip to content
Open
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
16 changes: 15 additions & 1 deletion edapi/edapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from edapi.types.api_types.endpoints.analytics import API_Analytics_Users_Response

from .types import EdAuthError, EdError, EditThreadParams, PostThreadParams
from .types import EdAuthError, EdError, EditThreadParams, PostThreadParams, PostCommentParams
from .types.api_types.endpoints.activity import (
API_ListUserActivity_Response,
API_ListUserActivity_Response_Item,
Expand Down Expand Up @@ -302,6 +302,20 @@ def post_thread(

_throw_error(f"Failed to post thread in course {course_id}.", response.content)

@_ensure_login
def post_comment(
self, thread_id: int, params: PostCommentParams
):
"""
Creates a new comment under the given thread.

POST /api/threads/<thread_id>/comments
"""
thread_url = urljoin(API_BASE_URL, f"threads/{thread_id}/comments")
response = self.session.post(thread_url, json={"comment": params})
if not response.ok:
_throw_error(f"Failed to post comment in thread {thread_id}.", response.content)

@_ensure_login
def edit_thread(
self, thread_id: int, params: EditThreadParams, unlock_thread=True
Expand Down
10 changes: 10 additions & 0 deletions edapi/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ class PostThreadParams(TypedDict, total=True):
is_anonymous: bool
is_megathread: bool
anonymous_comments: bool

class PostCommentParams(TypedDict, total=True):
"""
Parameters for posting a new comment.
All parameters are required.
"""
content: str
is_anonymous: bool
is_private: bool
type: str