3302c76e9c198e96d19c99dfa2f510713040909e
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
29 r
= self
._client
.session
.get(self
._client
.pod
+
33 if r
.status_code
== 200:
36 raise Exception('wrong status code: ' + str(r
.status_code
))
39 """This function likes a post
41 :returns: dict -- json formatted like object.
45 data
= {'authenticity_token': self
._client
.get_token()}
47 r
= self
._client
.session
.post(self
._client
.pod
+
52 headers
={'accept': 'application/json'})
54 if r
.status_code
!= 201:
55 raise Exception(str(r
.status_code
) + ': Post could not be liked.')
60 """This function removes a like from a post
64 data
= {'authenticity_token': self
._client
.get_token()}
66 post_data
= self
.fetch_data()
68 r
= self
._client
.session
.delete(self
._client
.pod
+ '/posts/' +
71 str(post_data
['interactions']
75 if r
.status_code
!= 204:
76 raise Exception(str(r
.status_code
) +
77 ': Like could not be removed.')
80 """This function reshares a post
84 post_data
= self
.fetch_data()
86 data
= {'root_guid': post_data
['guid'],
87 'authenticity_token': self
._client
.get_token()}
89 r
= self
._client
.session
.post(self
._client
.pod
+
92 headers
={'accept': 'application/json'})
94 if r
.status_code
!= 201:
95 raise Exception(str(r
.status_code
) +
96 ': Post could not be reshared.')
100 def comment(self
, text
):
101 """This function comments on a post
103 :param post_id: id of the post to comment on.
105 :param text: text to comment.
110 data
= {'text': text
,
111 'authenticity_token': self
._client
.get_token()}
113 r
= self
._client
.session
.post(self
._client
.pod
+
118 headers
={'accept': 'application/json'})
120 if r
.status_code
!= 201:
121 raise Exception(str(r
.status_code
) +
122 ': Comment could not be posted.')
126 def rmcomment(self
, comment_id
):
127 """This function removes a comment from a post
129 :param post_id: id of the post to remove the like from.
131 :param like_id: id of the like to remove.
136 data
= {'authenticity_token': self
._client
.get_token()}
138 r
= self
._client
.session
.delete(self
._client
.pod
+ '/posts/' +
143 headers
={'accept': 'application/json'})
145 if r
.status_code
!= 204:
146 raise Exception(str(r
.status_code
) +
147 ': Comment could not be deleted.')