66624f37a33c4b5ff61068d79949454103711f45
5 """This class represents a post.
8 Remember that you need to have access to the post.
9 Remember that you also need to be logged in.
11 def __init__(self
, post_id
, connection
):
13 :param post_id: id or guid of the post
15 :param connection: connection object used to authenticate
16 :type connection: connection.Connection
18 self
._connection
= connection
19 self
.post_id
= post_id
22 """This function retrieves data of the post.
24 r
= self
._connection
.get('posts/{0}.json'.format(self
.post_id
))
25 if r
.status_code
!= 200:
26 raise Exception('wrong status code: {0}'.format(r
.status_code
))
30 """This function likes a post.
31 It abstracts the 'Like' functionality.
33 :returns: dict -- json formatted like object.
35 data
= {'authenticity_token': self
._connection
.getToken()}
37 r
= self
._connection
.post('posts/{0}/likes'.format(self
.post_id
),
39 headers
={'accept': 'application/json'})
41 if r
.status_code
!= 201:
42 raise Exception('{0}: Post could not be liked.'
43 .format(r
.status_code
))
47 def delete_like(self
):
48 """This function removes a like from a post
50 data
= {'authenticity_token': self
._connection
.getToken()}
52 post_data
= self
.get_data()
54 r
= self
._connection
.delete('posts/{0}/likes/{1}'
56 post_data
['interactions']
60 if r
.status_code
!= 204:
61 raise Exception('{0}: Like could not be removed.'
62 .format(r
.status_code
))
65 """This function reshares a post
68 post_data
= self
.get_data()
70 data
= {'root_guid': post_data
['guid'],
71 'authenticity_token': self
._connection
.getToken()}
73 r
= self
._connection
.post('reshares',
75 headers
={'accept': 'application/json'})
77 if r
.status_code
!= 201:
78 raise Exception('{0}: Post could not be reshared.'
79 .format(r
.status_code
))
83 def comment(self
, text
):
84 """This function comments on a post
86 :param text: text to comment.
91 'authenticity_token': self
._connection
.getToken()}
93 r
= self
._connection
.post('posts/{0}/comments'.format(self
.post_id
),
95 headers
={'accept': 'application/json'})
97 if r
.status_code
!= 201:
98 raise Exception('{0}: Comment could not be posted.'
99 .format(r
.status_code
))
103 def delete_comment(self
, comment_id
):
104 """This function removes a comment from a post
106 :param comment_id: id of the comment to remove.
107 :type comment_id: str
110 data
= {'authenticity_token': self
._connection
.getToken()}
112 r
= self
._connection
.delete('posts/{0}/comments/{1}'
113 .format(self
.post_id
,
116 headers
={'accept': 'application/json'})
118 if r
.status_code
!= 204:
119 raise Exception('{0}: Comment could not be deleted.'
120 .format(r
.status_code
))
123 """ This function deletes this post
125 data
= {'authenticity_token': self
._connection
.getToken()}
126 r
= self
._connection
.delete('posts/{0}'.format(self
.post_id
),
128 headers
={'accept': 'application/json'})
129 if r
.status_code
!= 204:
130 raise Exception('{0}: Post could not be deleted'.format(r
.status_code
))