Skip to content

Commit

Permalink
Merge pull request #46 from icamacho3/develop
Browse files Browse the repository at this point in the history
Update post functionality
  • Loading branch information
hfaran authored Aug 6, 2019
2 parents 26201d0 + cc3c5cf commit 2c6c49c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 24 deletions.
73 changes: 49 additions & 24 deletions piazza_api/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,31 @@ def create_reply(self, post, content, anonymous=False):
}
return self._rpc.content_create(params)

def update_post(self, post, content):
"""Update post content by cid
: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.
:rtype: dict
:returns: Dictionary with information about the updated post.
"""
try:
cid = post["id"]
except KeyError:
cid = post
except TypeError:
cid = post

params = {
"cid": cid,
# For updates, the content is put into the subject.
"subject": content,
}
return self._rpc.content_update(params)

def mark_as_duplicate(self, duplicated_cid, master_cid, msg=''):
"""Mark the post at ``duplicated_cid`` as a duplicate of ``master_cid``
Expand Down Expand Up @@ -306,6 +331,30 @@ def pin_post(self, post):

return self._rpc.content_pin(params)

def delete_post(self, post):
""" Deletes post by cid
:type post: dict|str|int
:param post: Either the post dict returned by another API method, the post ID, or
the `cid` field of that post.
:rtype: dict
:returns: Dictionary with information about the post cid.
"""

try:
cid = post['id']
except KeyError:
cid = post
except TypeError:
post = self.get_post(post)
cid = post['id']

params = {
"cid": cid,
}

return self._rpc.content_delete(params)

#########
# Users #
#########
Expand Down Expand Up @@ -375,30 +424,6 @@ def remove_users(self, user_ids):
"""
return self._rpc.remove_users(user_ids=user_ids)

def delete_post(self, post):
""" Deletes post by cid
:type post: dict|str|int
:param post: Either the post dict returned by another API method, the post ID, or
the `cid` field of that post.
:rtype: dict
:returns: Dictionary with information about the post cid.
"""

try:
cid = post['id']
except KeyError:
cid = post
except TypeError:
post = self.get_post(post)
cid = post['id']

params = {
"cid": cid,
}

return self._rpc.content_delete(params)

########
# Feed #
########
Expand Down
17 changes: 17 additions & 0 deletions piazza_api/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ def content_create(self, params):
"Could not create object {}.".format(repr(params))
)

def content_update(self, params):
"""Update 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.update",
data=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.
Expand Down

0 comments on commit 2c6c49c

Please sign in to comment.