Skip to content

Commit

Permalink
Merge pull request #26 from hfaran/develop
Browse files Browse the repository at this point in the history
develop -> master for 0.5.0
  • Loading branch information
hfaran committed May 25, 2015
2 parents 742fdd1 + 8d960ea commit 6a18f3a
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 7 deletions.
10 changes: 7 additions & 3 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@

## Creator & Maintainer

* Hamza Faran [@hfaran](github.com/hfaran)
* Hamza Faran [@hfaran](https://github.com/hfaran)


## Contributors

* Philip Mallory [@pmallory](github.com/pmallory)
* Philip Mallory [@pmallory](https://github.com/pmallory)
* Enroll users
* Get all users
* Remove users

* Ben Cook [@blx](github.com/blx)
* Ben Cook [@blx](https://github.com/blx)
* Get users
* `PiazzaRPC.request`
* [`Piazza.get_user_classes`](https://github.com/hfaran/piazza-api/pull/22)

* Waleed Khan [@arxanas](https://github.com/arxanas)
- [`Network.create_followup`](https://github.com/hfaran/piazza-api/pull/25)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ sudo python setup.py install
## Contribute

* [Issue Tracker](https://github.com/hfaran/piazza-api/issues)
* [Source Code](github.com/hfaran/piazza-api)
* [Source Code](https://github.com/hfaran/piazza-api)

### Commit Message Guidelines

Expand Down
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.4.1"
__version__ = "0.5.0"
38 changes: 36 additions & 2 deletions piazza_api/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,40 @@ def iter_all_posts(self, limit=None):
for cid in cids:
yield self.get_post(cid)

def create_followup(self, post, content, anonymous=False):
"""Create a follow-up on 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 subject: str
:param content: The content of the followup.
:type anonymous: bool
:param anonymous: Whether or not to post anonymously.
:rtype: dict
:returns: Dictionary with information about the created follow-up.
"""
try:
cid = post["id"]
except KeyError:
cid = post

params = {
"cid": cid,
"type": "followup",

# For followups, the content is actually put into the subject.
"subject": content,
"content": "",

"anonymous": "yes" if anonymous else "no",
}
return self._rpc.content_create(params)

#########
# Users #
#########
Expand All @@ -113,8 +147,8 @@ def get_users(self, user_ids):
"""Get a listing of data for specific users ``user_ids`` in
this network
:type user_ids: list of str
:param user_ids: a list of user ids. These are the same
:type user_ids: list
:param user_ids: A list of user ids (strings). These are the same
ids that are returned by get_all_users.
:returns: Python object containing returned data, a list
of dicts containing user data.
Expand Down
18 changes: 18 additions & 0 deletions piazza_api/piazza.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,23 @@ def get_user_profile(self):
"""
return self._rpc_api.get_user_profile()

def get_user_classes(self):
"""Get list of the current user's classes. This is a subset of
``get_user_profile``.
:returns: Classes of currently authenticated user
:rtype: list
"""
raw_classes = self.get_user_profile().get('all_classes').values()

classes = []
for rawc in raw_classes:
c = {k: rawc[k] for k in ['name', 'num', 'term']}
c['nid'] = rawc['id']
c['is_ta'] = rawc.get('is_ta', False)
classes.append(c)

return classes

def _ensure_authenticated(self):
self._rpc_api._check_authenticated()
15 changes: 15 additions & 0 deletions piazza_api/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ def content_get(self, cid, nid=None):
)
return self._handle_error(r, "Could not get post {}.".format(cid))

def content_create(self, params):
"""Create 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.create",
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 6a18f3a

Please sign in to comment.