Skip to content

Commit 2c6c49c

Browse files
authored
Merge pull request #46 from icamacho3/develop
Update post functionality
2 parents 26201d0 + cc3c5cf commit 2c6c49c

File tree

2 files changed

+66
-24
lines changed

2 files changed

+66
-24
lines changed

piazza_api/network.py

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,31 @@ def create_reply(self, post, content, anonymous=False):
245245
}
246246
return self._rpc.content_create(params)
247247

248+
def update_post(self, post, content):
249+
"""Update post content by cid
250+
251+
:type post: dict|str|int
252+
:param post: Either the post dict returned by another API method, or
253+
the `cid` field of that post.
254+
:type subject: str
255+
:param content: The content of the followup.
256+
:rtype: dict
257+
:returns: Dictionary with information about the updated post.
258+
"""
259+
try:
260+
cid = post["id"]
261+
except KeyError:
262+
cid = post
263+
except TypeError:
264+
cid = post
265+
266+
params = {
267+
"cid": cid,
268+
# For updates, the content is put into the subject.
269+
"subject": content,
270+
}
271+
return self._rpc.content_update(params)
272+
248273
def mark_as_duplicate(self, duplicated_cid, master_cid, msg=''):
249274
"""Mark the post at ``duplicated_cid`` as a duplicate of ``master_cid``
250275
@@ -306,6 +331,30 @@ def pin_post(self, post):
306331

307332
return self._rpc.content_pin(params)
308333

334+
def delete_post(self, post):
335+
""" Deletes post by cid
336+
337+
:type post: dict|str|int
338+
:param post: Either the post dict returned by another API method, the post ID, or
339+
the `cid` field of that post.
340+
:rtype: dict
341+
:returns: Dictionary with information about the post cid.
342+
"""
343+
344+
try:
345+
cid = post['id']
346+
except KeyError:
347+
cid = post
348+
except TypeError:
349+
post = self.get_post(post)
350+
cid = post['id']
351+
352+
params = {
353+
"cid": cid,
354+
}
355+
356+
return self._rpc.content_delete(params)
357+
309358
#########
310359
# Users #
311360
#########
@@ -375,30 +424,6 @@ def remove_users(self, user_ids):
375424
"""
376425
return self._rpc.remove_users(user_ids=user_ids)
377426

378-
def delete_post(self, post):
379-
""" Deletes post by cid
380-
381-
:type post: dict|str|int
382-
:param post: Either the post dict returned by another API method, the post ID, or
383-
the `cid` field of that post.
384-
:rtype: dict
385-
:returns: Dictionary with information about the post cid.
386-
"""
387-
388-
try:
389-
cid = post['id']
390-
except KeyError:
391-
cid = post
392-
except TypeError:
393-
post = self.get_post(post)
394-
cid = post['id']
395-
396-
params = {
397-
"cid": cid,
398-
}
399-
400-
return self._rpc.content_delete(params)
401-
402427
########
403428
# Feed #
404429
########

piazza_api/rpc.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,23 @@ def content_create(self, params):
114114
"Could not create object {}.".format(repr(params))
115115
)
116116

117+
def content_update(self, params):
118+
"""Update a post or followup.
119+
120+
:type params: dict
121+
:param params: A dict of options to pass to the endpoint. Depends on
122+
the specific type of content being created.
123+
:returns: Python object containing returned data
124+
"""
125+
r = self.request(
126+
method="content.update",
127+
data=params
128+
)
129+
return self._handle_error(
130+
r,
131+
"Could not create object {}.".format(repr(params))
132+
)
133+
117134
def content_instructor_answer(self, params):
118135
"""Answer a post as an instructor.
119136

0 commit comments

Comments
 (0)