Skip to content

Commit 6a18f3a

Browse files
committed
Merge pull request #26 from hfaran/develop
develop -> master for 0.5.0
2 parents 742fdd1 + 8d960ea commit 6a18f3a

File tree

6 files changed

+78
-7
lines changed

6 files changed

+78
-7
lines changed

CONTRIBUTORS.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44

55
## Creator & Maintainer
66

7-
* Hamza Faran [@hfaran](github.com/hfaran)
7+
* Hamza Faran [@hfaran](https://github.com/hfaran)
88

99

1010
## Contributors
1111

12-
* Philip Mallory [@pmallory](github.com/pmallory)
12+
* Philip Mallory [@pmallory](https://github.com/pmallory)
1313
* Enroll users
1414
* Get all users
1515
* Remove users
1616

17-
* Ben Cook [@blx](github.com/blx)
17+
* Ben Cook [@blx](https://github.com/blx)
1818
* Get users
1919
* `PiazzaRPC.request`
20+
* [`Piazza.get_user_classes`](https://github.com/hfaran/piazza-api/pull/22)
21+
22+
* Waleed Khan [@arxanas](https://github.com/arxanas)
23+
- [`Network.create_followup`](https://github.com/hfaran/piazza-api/pull/25)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ sudo python setup.py install
6868
## Contribute
6969

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

7373
### Commit Message Guidelines
7474

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.4.1"
3+
__version__ = "0.5.0"

piazza_api/network.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,40 @@ def iter_all_posts(self, limit=None):
105105
for cid in cids:
106106
yield self.get_post(cid)
107107

108+
def create_followup(self, post, content, anonymous=False):
109+
"""Create a follow-up on a post `post`.
110+
111+
It seems like if the post has `<p>` tags, then it's treated as HTML,
112+
but is treated as text otherwise. You'll want to provide `content`
113+
accordingly.
114+
115+
:type post: dict|str|int
116+
:param post: Either the post dict returned by another API method, or
117+
the `cid` field of that post.
118+
:type subject: str
119+
:param content: The content of the followup.
120+
:type anonymous: bool
121+
:param anonymous: Whether or not to post anonymously.
122+
:rtype: dict
123+
:returns: Dictionary with information about the created follow-up.
124+
"""
125+
try:
126+
cid = post["id"]
127+
except KeyError:
128+
cid = post
129+
130+
params = {
131+
"cid": cid,
132+
"type": "followup",
133+
134+
# For followups, the content is actually put into the subject.
135+
"subject": content,
136+
"content": "",
137+
138+
"anonymous": "yes" if anonymous else "no",
139+
}
140+
return self._rpc.content_create(params)
141+
108142
#########
109143
# Users #
110144
#########
@@ -113,8 +147,8 @@ def get_users(self, user_ids):
113147
"""Get a listing of data for specific users ``user_ids`` in
114148
this network
115149
116-
:type user_ids: list of str
117-
:param user_ids: a list of user ids. These are the same
150+
:type user_ids: list
151+
:param user_ids: A list of user ids (strings). These are the same
118152
ids that are returned by get_all_users.
119153
:returns: Python object containing returned data, a list
120154
of dicts containing user data.

piazza_api/piazza.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,23 @@ def get_user_profile(self):
5353
"""
5454
return self._rpc_api.get_user_profile()
5555

56+
def get_user_classes(self):
57+
"""Get list of the current user's classes. This is a subset of
58+
``get_user_profile``.
59+
60+
:returns: Classes of currently authenticated user
61+
:rtype: list
62+
"""
63+
raw_classes = self.get_user_profile().get('all_classes').values()
64+
65+
classes = []
66+
for rawc in raw_classes:
67+
c = {k: rawc[k] for k in ['name', 'num', 'term']}
68+
c['nid'] = rawc['id']
69+
c['is_ta'] = rawc.get('is_ta', False)
70+
classes.append(c)
71+
72+
return classes
73+
5674
def _ensure_authenticated(self):
5775
self._rpc_api._check_authenticated()

piazza_api/rpc.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ def content_get(self, cid, nid=None):
9696
)
9797
return self._handle_error(r, "Could not get post {}.".format(cid))
9898

99+
def content_create(self, params):
100+
"""Create a post or followup.
101+
102+
:type params: dict
103+
:param params: A dict of options to pass to the endpoint. Depends on
104+
the specific type of content being created.
105+
:returns: Python object containing returned data
106+
"""
107+
r = self.request(
108+
method="content.create",
109+
data=params
110+
)
111+
return self._handle_error(r, "Could not create object {}.".format(
112+
repr(params)))
113+
99114
def add_students(self, student_emails, nid=None):
100115
"""Enroll students in a network `nid`.
101116

0 commit comments

Comments
 (0)