Skip to content

Commit

Permalink
Merge pull request #32 from hfaran/develop
Browse files Browse the repository at this point in the history
develop -> master for 0.5.2
  • Loading branch information
hfaran committed Mar 19, 2016
2 parents 4733504 + 8aab11b commit a994317
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion piazza_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from piazza_api.piazza import Piazza

__version__ = "0.5.1"
__version__ = "0.5.2"
34 changes: 34 additions & 0 deletions piazza_api/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
#########
Expand Down
16 changes: 16 additions & 0 deletions piazza_api/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit a994317

Please sign in to comment.