From c8626ec57874c0b38666edb6068b662bd8ea8744 Mon Sep 17 00:00:00 2001 From: DavidSnider <sniderdj@umich.edu> Date: Fri, 18 Mar 2016 00:35:09 -0400 Subject: [PATCH 1/2] feat(user): Add answer-creating functionality --- piazza_api/network.py | 34 ++++++++++++++++++++++++++++++++++ piazza_api/rpc.py | 16 ++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/piazza_api/network.py b/piazza_api/network.py index a9d1d24..1bca87a 100644 --- a/piazza_api/network.py +++ b/piazza_api/network.py @@ -139,6 +139,40 @@ def create_followup(self, post, content, anonymous=False): } return self._rpc.content_create(params) + def create_instructor_answer(self, post, content, revision, anonymous=False): + """Create an instructor's answer to a post `post`. + + It seems like if the post has `<p>` tags, then it's treated as HTML, + but is treated as text otherwise. You'll want to provide `content` + accordingly. + + :type post: dict|str|int + :param post: Either the post dict returned by another API method, or + the `cid` field of that post. + :type content: str + :param content: The content of the answer. + :type revision: int + :param revision: The number of revisions the answer has gone through. + The first responder should out 0, the first editor 1, etc. + :type anonymous: bool + :param anonymous: Whether or not to post anonymously. + :rtype: dict + :returns: Dictionary with information about the created answer. + """ + try: + cid = post["id"] + except KeyError: + cid = post + + params = { + "cid": cid, + "type": "i_answer", + "content": content, + "revision": revision, + "anonymous": "yes" if anonymous else "no", + } + return self._rpc.content_instructor_answer(params) + ######### # Users # ######### diff --git a/piazza_api/rpc.py b/piazza_api/rpc.py index 0e8d837..c52ed26 100644 --- a/piazza_api/rpc.py +++ b/piazza_api/rpc.py @@ -111,6 +111,22 @@ def content_create(self, 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. + + :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.answer", + data=params + ) + return self._handle_error(r, "Could not create object {}.".format( + repr(params))) + + def add_students(self, student_emails, nid=None): """Enroll students in a network `nid`. From 8aab11b133ac193be8ee6a6cdcc73cd3417bb456 Mon Sep 17 00:00:00 2001 From: hfaran <hamzafaran@outlook.com> Date: Fri, 18 Mar 2016 17:27:06 -0700 Subject: [PATCH 2/2] Release 0.5.2 --- CONTRIBUTORS.md | 3 +++ piazza_api/__init__.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 43b11bf..ae63350 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -21,3 +21,6 @@ * Waleed Khan [@arxanas](https://github.com/arxanas) - [`Network.create_followup`](https://github.com/hfaran/piazza-api/pull/25) + +* [@DavidSnider](https://github.com/DavidSnider) + - [feat(user): Add answer-creating functionality](https://github.com/hfaran/piazza-api/pull/31) diff --git a/piazza_api/__init__.py b/piazza_api/__init__.py index 147ab5c..378e973 100644 --- a/piazza_api/__init__.py +++ b/piazza_api/__init__.py @@ -1,3 +1,3 @@ from piazza_api.piazza import Piazza -__version__ = "0.5.1" +__version__ = "0.5.2"