From 1451907a02140a74cc16cb7ad495d7410d287bc0 Mon Sep 17 00:00:00 2001 From: Rolando Evaristo Date: Mon, 6 Nov 2017 08:58:47 +0800 Subject: [PATCH 1/2] Area updated. Adds Comment object. Added the following methods: Comment.create() Comment.update() Comment.find_all() Comment.revisions() Comment.find() Comment.delete() --- pypodio2/areas.py | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/pypodio2/areas.py b/pypodio2/areas.py index cfd60f0..d0473b6 100644 --- a/pypodio2/areas.py +++ b/pypodio2/areas.py @@ -613,3 +613,78 @@ def update_view(self, view_id, attributes): return self.transport.PUT(url='/view/{}'.format(view_id), body=attribute_data, type='application/json') + +class Comment(Area): + + def create(self, ref_type, ref_id, attributes): + """ + Post a comment on specified app item + + :param ref_type: Object Reference type + :param ref_id: Object Reference ID + :param attributes: the body of the request as a dictionary + :return: Details of comment + :rtype: dict + """ + if type(attributes) != dict: + raise TypeError('Must be of type dict') + attributes = json.dumps(attributes) + return self.transport.POST(url='/comment/{}/{}/'.format(ref_type, ref_id), + body=attributes, type='application/json') + + + def update(self, comment_id, attributes, silent=False, hook=True): + """ + Edit or update a comment + + :param comment_id: Comment ID to edit + :param attributes: the body of the request as a dictionary + """ + if not isinstance(attributes, dict): + raise TypeError('Must be of type dict') + attributes = json.dumps(attributes) + return self.transport.PUT(body=attributes, + type='application/json', + url='/comment/%d%s' % (comment_id, self.get_options(silent=silent, + hook=hook))) + + def find_all(self, ref_type, ref_id): + """ + Find all of the comments of an object reference + + :param ref_type: Object reference type + :param ref_id: Object Reference ID + :return: Details of comments + :rtype: dict + """ + return self.transport.GET(url='/comment/{}/{}'.format(ref_type, ref_id)) + + def revisions(self, comment_id): + """ + Returns revisions of given comment + + :param comment_id: Comment ID + :return: Details of comments revisions + :rtype: dict + """ + return self.transport.GET(url='/comment/{}/revision'.format(comment_id)) + + + def find(self, comment_id): + """ + Find single comment details + + :param comment_id: Comment ID + :return: Details of comment + :rtype: dict + """ + return self.transport.GET(url='/comment//{}'.format(comment_id)) + + def delete(self, comment_id): + """ + Remove comment from reference + + :param comment_id: Comment ID + """ + return self.transport.DELETE(url='/comment/{}'.format(comment_id)) + From 1ac684401924efe3bd68b3f70954de2ff84cca87 Mon Sep 17 00:00:00 2001 From: Rolando Evaristo Date: Mon, 6 Nov 2017 09:23:57 +0800 Subject: [PATCH 2/2] remove double slash on transport URL of Comment.find() method --- pypodio2/areas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pypodio2/areas.py b/pypodio2/areas.py index d0473b6..0221e38 100644 --- a/pypodio2/areas.py +++ b/pypodio2/areas.py @@ -678,7 +678,7 @@ def find(self, comment_id): :return: Details of comment :rtype: dict """ - return self.transport.GET(url='/comment//{}'.format(comment_id)) + return self.transport.GET(url='/comment/{}'.format(comment_id)) def delete(self, comment_id): """