5 """This class represents a post.
8 Remember that you need to have access to the post.
12 def __init__(self
, post_id
, client
):
14 :param post_id: id or guid of the post
16 :param client: client object used to authenticate
17 :type client: client.Client
20 The login function of the client should be called,
21 before calling any of the post functions.
25 self
.post_id
= post_id
28 r
= self
._client
.session
.get(self
._client
.pod
+
32 if r
.status_code
== 200:
35 raise Exception('wrong status code: ' + str(r
.status_code
))
38 """This function likes a post
40 :returns: dict -- json formatted like object.
44 data
= {'authenticity_token': self
._client
.get_token()}
46 r
= self
._client
.session
.post(self
._client
.pod
+
51 headers
={'accept': 'application/json'})
53 if r
.status_code
!= 201:
54 raise Exception(str(r
.status_code
) + ': Post could not be liked.')
58 def delete_like(self
):
59 """This function removes a like from a post
63 data
= {'authenticity_token': self
._client
.get_token()}
65 post_data
= self
.get_data()
67 r
= self
._client
.session
.delete(self
._client
.pod
+ '/posts/' +
70 str(post_data
['interactions']
74 if r
.status_code
!= 204:
75 raise Exception(str(r
.status_code
) +
76 ': Like could not be removed.')
79 """This function reshares a post
83 post_data
= self
.get_data()
85 data
= {'root_guid': post_data
['guid'],
86 'authenticity_token': self
._client
.get_token()}
88 r
= self
._client
.session
.post(self
._client
.pod
+
91 headers
={'accept': 'application/json'})
93 if r
.status_code
!= 201:
94 raise Exception(str(r
.status_code
) +
95 ': Post could not be reshared.')
99 def comment(self
, text
):
100 """This function comments on a post
102 :param post_id: id of the post to comment on.
104 :param text: text to comment.
109 data
= {'text': text
,
110 'authenticity_token': self
._client
.get_token()}
112 r
= self
._client
.session
.post(self
._client
.pod
+
117 headers
={'accept': 'application/json'})
119 if r
.status_code
!= 201:
120 raise Exception(str(r
.status_code
) +
121 ': Comment could not be posted.')
125 def delete_comment(self
, comment_id
):
126 """This function removes a comment from a post
128 :param post_id: id of the post to remove the like from.
130 :param like_id: id of the like to remove.
135 data
= {'authenticity_token': self
._client
.get_token()}
137 r
= self
._client
.session
.delete(self
._client
.pod
+ '/posts/' +
142 headers
={'accept': 'application/json'})
144 if r
.status_code
!= 204:
145 raise Exception(str(r
.status_code
) +
146 ': Comment could not be deleted.')
149 """ This function deletes this post
153 data
= {'authenticity_token': self
._client
.get_token()}
155 r
= self
._client
.session
.delete(self
._client
.pod
+ '/posts/' +
158 headers
={'accept': 'application/json'})