diff --git a/piazza_api/network.py b/piazza_api/network.py index 929a01e..ea8724d 100644 --- a/piazza_api/network.py +++ b/piazza_api/network.py @@ -245,6 +245,31 @@ def create_reply(self, post, content, anonymous=False): } return self._rpc.content_create(params) + def update_post(self, post, content): + """Update post content by cid + + :type post: dict|str|int + :param post: Either the post dict returned by another API method, or + the `cid` field of that post. + :type subject: str + :param content: The content of the followup. + :rtype: dict + :returns: Dictionary with information about the updated post. + """ + try: + cid = post["id"] + except KeyError: + cid = post + except TypeError: + cid = post + + params = { + "cid": cid, + # For updates, the content is put into the subject. + "subject": content, + } + return self._rpc.content_update(params) + def mark_as_duplicate(self, duplicated_cid, master_cid, msg=''): """Mark the post at ``duplicated_cid`` as a duplicate of ``master_cid`` @@ -306,6 +331,30 @@ def pin_post(self, post): return self._rpc.content_pin(params) + def delete_post(self, post): + """ Deletes post by cid + + :type post: dict|str|int + :param post: Either the post dict returned by another API method, the post ID, or + the `cid` field of that post. + :rtype: dict + :returns: Dictionary with information about the post cid. + """ + + try: + cid = post['id'] + except KeyError: + cid = post + except TypeError: + post = self.get_post(post) + cid = post['id'] + + params = { + "cid": cid, + } + + return self._rpc.content_delete(params) + ######### # Users # ######### @@ -375,30 +424,6 @@ def remove_users(self, user_ids): """ return self._rpc.remove_users(user_ids=user_ids) - def delete_post(self, post): - """ Deletes post by cid - - :type post: dict|str|int - :param post: Either the post dict returned by another API method, the post ID, or - the `cid` field of that post. - :rtype: dict - :returns: Dictionary with information about the post cid. - """ - - try: - cid = post['id'] - except KeyError: - cid = post - except TypeError: - post = self.get_post(post) - cid = post['id'] - - params = { - "cid": cid, - } - - return self._rpc.content_delete(params) - ######## # Feed # ######## diff --git a/piazza_api/rpc.py b/piazza_api/rpc.py index 224af70..13cbe39 100644 --- a/piazza_api/rpc.py +++ b/piazza_api/rpc.py @@ -114,6 +114,23 @@ def content_create(self, params): "Could not create object {}.".format(repr(params)) ) + def content_update(self, params): + """Update a post or followup. + + :type params: dict + :param params: A dict of options to pass to the endpoint. Depends on + the specific type of content being created. + :returns: Python object containing returned data + """ + r = self.request( + method="content.update", + data=params + ) + return self._handle_error( + r, + "Could not create object {}.".format(repr(params)) + ) + def content_instructor_answer(self, params): """Answer a post as an instructor.