From 9980f1de182abe1c0db0c10e6e1727d582b8d6f2 Mon Sep 17 00:00:00 2001 From: Ben Cook Date: Sun, 11 Jan 2015 00:53:12 -0800 Subject: [PATCH 01/11] feat(user): Add get_user_classes convenience method --- piazza_api/piazza.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/piazza_api/piazza.py b/piazza_api/piazza.py index 9896872..b2e73d3 100644 --- a/piazza_api/piazza.py +++ b/piazza_api/piazza.py @@ -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() From 3e0d13fc9286e3fd29f0dd7e15bf17d6cea6e564 Mon Sep 17 00:00:00 2001 From: Hamza Faran Date: Sun, 11 Jan 2015 01:18:26 -0800 Subject: [PATCH 02/11] Update CONTRIBUTORS.md --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index daeb23e..d21d352 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -17,3 +17,4 @@ * Ben Cook [@blx](github.com/blx) * Get users * `PiazzaRPC.request` + * [`Piazza.get_user_classes`](https://github.com/hfaran/piazza-api/pull/22) From e165825797383daad17fd16b3bbca0611a993306 Mon Sep 17 00:00:00 2001 From: hfaran Date: Mon, 12 Jan 2015 09:58:12 -0800 Subject: [PATCH 03/11] docs(dev): Fix type in docstr" --- piazza_api/network.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/piazza_api/network.py b/piazza_api/network.py index 40a6bc2..fed646f 100644 --- a/piazza_api/network.py +++ b/piazza_api/network.py @@ -113,8 +113,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. From fda0aa97a81e855db5d70bdf9aedb1574396a2b4 Mon Sep 17 00:00:00 2001 From: Ben Cook Date: Tue, 13 Jan 2015 10:26:58 -0800 Subject: [PATCH 04/11] docs(user): Fix links in Contributors.md --- CONTRIBUTORS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index d21d352..3c8d5f6 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -4,17 +4,17 @@ ## 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) From f53e348ceca46987b0cdb2505ea6a79f76413696 Mon Sep 17 00:00:00 2001 From: Ben Cook Date: Tue, 13 Jan 2015 10:48:29 -0800 Subject: [PATCH 05/11] docs(user): Fix link in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 692a682..7df4e6f 100644 --- a/README.md +++ b/README.md @@ -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 From fb3b5640a66499e9ef5621ca0f069e687d56b176 Mon Sep 17 00:00:00 2001 From: Waleed Khan Date: Sat, 23 May 2015 21:20:08 -0700 Subject: [PATCH 06/11] feat(user): Add followup-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 fed646f..01317e8 100644 --- a/piazza_api/network.py +++ b/piazza_api/network.py @@ -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 `

` 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 # ######### diff --git a/piazza_api/rpc.py b/piazza_api/rpc.py index 2f09607..bc81d4e 100644 --- a/piazza_api/rpc.py +++ b/piazza_api/rpc.py @@ -96,6 +96,22 @@ 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", + # blank. + 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 6fefacaf7b4bc28d5fff6673e6b77f7fbfe1ac78 Mon Sep 17 00:00:00 2001 From: Waleed Khan Date: Sun, 24 May 2015 11:26:57 -0700 Subject: [PATCH 07/11] docs(dev): Fix comments for create_followup. --- piazza_api/network.py | 2 +- piazza_api/rpc.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/piazza_api/network.py b/piazza_api/network.py index 01317e8..a9d1d24 100644 --- a/piazza_api/network.py +++ b/piazza_api/network.py @@ -114,7 +114,7 @@ def create_followup(self, post, content, anonymous=False): :type post: dict|str|int :param post: Either the post dict returned by another API method, or - the cid` field of that post. + the `cid` field of that post. :type subject: str :param content: The content of the followup. :type anonymous: bool diff --git a/piazza_api/rpc.py b/piazza_api/rpc.py index bc81d4e..0e8d837 100644 --- a/piazza_api/rpc.py +++ b/piazza_api/rpc.py @@ -106,7 +106,6 @@ def content_create(self, params): """ r = self.request( method="content.create", - # blank. data=params ) return self._handle_error(r, "Could not create object {}.".format( From 13b442bc38000a7374dceab9dcc8c8572dfad2a2 Mon Sep 17 00:00:00 2001 From: Waleed Khan Date: Sun, 24 May 2015 11:29:30 -0700 Subject: [PATCH 08/11] feat(user): Update version number for create_followup. --- piazza_api/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piazza_api/__init__.py b/piazza_api/__init__.py index 30c3b8a..586a778 100644 --- a/piazza_api/__init__.py +++ b/piazza_api/__init__.py @@ -1,3 +1,3 @@ from piazza_api.piazza import Piazza -__version__ = "0.4.1" +__version__ = "0.4.2" From 5a70f0f395d1b17228c291511f708782f3f7dcda Mon Sep 17 00:00:00 2001 From: Waleed Khan Date: Sun, 24 May 2015 17:15:32 -0700 Subject: [PATCH 09/11] revert(user) "feat(user): Update version number for create_followup." This reverts commit 13b442bc38000a7374dceab9dcc8c8572dfad2a2. --- piazza_api/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piazza_api/__init__.py b/piazza_api/__init__.py index 586a778..30c3b8a 100644 --- a/piazza_api/__init__.py +++ b/piazza_api/__init__.py @@ -1,3 +1,3 @@ from piazza_api.piazza import Piazza -__version__ = "0.4.2" +__version__ = "0.4.1" From c3104cdcd075b154b51be4d54be1aabc3de42a9c Mon Sep 17 00:00:00 2001 From: hfaran Date: Sun, 24 May 2015 17:28:10 -0700 Subject: [PATCH 10/11] Release 0.5.0 --- piazza_api/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piazza_api/__init__.py b/piazza_api/__init__.py index 30c3b8a..af98262 100644 --- a/piazza_api/__init__.py +++ b/piazza_api/__init__.py @@ -1,3 +1,3 @@ from piazza_api.piazza import Piazza -__version__ = "0.4.1" +__version__ = "0.5.0" From 8d960ea6b035353bf66b7b70edc8f49d747a4760 Mon Sep 17 00:00:00 2001 From: hfaran Date: Sun, 24 May 2015 17:34:12 -0700 Subject: [PATCH 11/11] docs(dev): Add @arxanas as contributor --- CONTRIBUTORS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 3c8d5f6..43b11bf 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -18,3 +18,6 @@ * 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)