From 0783001307554a60111c689d83237bc7594cf9fd Mon Sep 17 00:00:00 2001 From: Ida Date: Sat, 27 Jul 2019 21:20:34 -0700 Subject: [PATCH 1/3] Moved delete_post to "Posts" section Added update_post and content_update, which updates post content by cid --- piazza_api/network.py | 72 ++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/piazza_api/network.py b/piazza_api/network.py index 929a01e..f3c1c6c 100644 --- a/piazza_api/network.py +++ b/piazza_api/network.py @@ -245,6 +245,30 @@ 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 + + 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 +330,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 +423,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 # ######## From 0c728cd247eeb599db7ac1f2531fc2647d532438 Mon Sep 17 00:00:00 2001 From: Ida Date: Sat, 27 Jul 2019 21:23:10 -0700 Subject: [PATCH 2/3] Update a post or followup with content_update --- piazza_api/rpc.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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. From cc3c5cf0ccc678aaec0efba3d87c9b89555b48a8 Mon Sep 17 00:00:00 2001 From: Ida Date: Tue, 6 Aug 2019 03:37:28 -0700 Subject: [PATCH 3/3] Update content_update with TypeError exception --- piazza_api/network.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/piazza_api/network.py b/piazza_api/network.py index f3c1c6c..ea8724d 100644 --- a/piazza_api/network.py +++ b/piazza_api/network.py @@ -260,10 +260,11 @@ def update_post(self, post, content): 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, }