Skip to content

Commit a994317

Browse files
committed
Merge pull request #32 from hfaran/develop
develop -> master for 0.5.2
2 parents 4733504 + 8aab11b commit a994317

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

CONTRIBUTORS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@
2121

2222
* Waleed Khan [@arxanas](https://github.com/arxanas)
2323
- [`Network.create_followup`](https://github.com/hfaran/piazza-api/pull/25)
24+
25+
* [@DavidSnider](https://github.com/DavidSnider)
26+
- [feat(user): Add answer-creating functionality](https://github.com/hfaran/piazza-api/pull/31)

piazza_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from piazza_api.piazza import Piazza
22

3-
__version__ = "0.5.1"
3+
__version__ = "0.5.2"

piazza_api/network.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,40 @@ def create_followup(self, post, content, anonymous=False):
139139
}
140140
return self._rpc.content_create(params)
141141

142+
def create_instructor_answer(self, post, content, revision, anonymous=False):
143+
"""Create an instructor's answer to a post `post`.
144+
145+
It seems like if the post has `<p>` tags, then it's treated as HTML,
146+
but is treated as text otherwise. You'll want to provide `content`
147+
accordingly.
148+
149+
:type post: dict|str|int
150+
:param post: Either the post dict returned by another API method, or
151+
the `cid` field of that post.
152+
:type content: str
153+
:param content: The content of the answer.
154+
:type revision: int
155+
:param revision: The number of revisions the answer has gone through.
156+
The first responder should out 0, the first editor 1, etc.
157+
:type anonymous: bool
158+
:param anonymous: Whether or not to post anonymously.
159+
:rtype: dict
160+
:returns: Dictionary with information about the created answer.
161+
"""
162+
try:
163+
cid = post["id"]
164+
except KeyError:
165+
cid = post
166+
167+
params = {
168+
"cid": cid,
169+
"type": "i_answer",
170+
"content": content,
171+
"revision": revision,
172+
"anonymous": "yes" if anonymous else "no",
173+
}
174+
return self._rpc.content_instructor_answer(params)
175+
142176
#########
143177
# Users #
144178
#########

piazza_api/rpc.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ def content_create(self, params):
111111
return self._handle_error(r, "Could not create object {}.".format(
112112
repr(params)))
113113

114+
def content_instructor_answer(self, params):
115+
"""Answer a post as an instructor.
116+
117+
:type params: dict
118+
:param params: A dict of options to pass to the endpoint. Depends on
119+
the specific type of content being created.
120+
:returns: Python object containing returned data
121+
"""
122+
r = self.request(
123+
method="content.answer",
124+
data=params
125+
)
126+
return self._handle_error(r, "Could not create object {}.".format(
127+
repr(params)))
128+
129+
114130
def add_students(self, student_emails, nid=None):
115131
"""Enroll students in a network `nid`.
116132

0 commit comments

Comments
 (0)