4700d21f6bf943feb438eb0ad91ce73bb954fdf4
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.
26 r
= self
._client
.session
.get(self
._client
.pod
+
30 if r
.status_code
== 200:
33 raise Exception('wrong status code: ' + str(r
.status_code
))
36 """This function likes a post
38 :returns: dict -- json formatted like object.
42 data
= {'authenticity_token': self
._client
.get_token()}
44 r
= self
._client
.session
.post(self
._client
.pod
+
46 str(self
.data
['id']) +
49 headers
={'accept': 'application/json'})
51 if r
.status_code
!= 201:
52 raise Exception(str(r
.status_code
) + ': Post could not be liked.')
57 """This function removes a like from a post
61 data
= {'authenticity_token': self
._client
.get_token()}
63 r
= self
._client
.session
.delete(self
._client
.pod
+ '/posts/' +
64 str(self
.data
['id']) +
66 str(self
.data
['interactions']
70 if r
.status_code
!= 204:
71 raise Exception(str(r
.status_code
) +
72 ': Like could not be removed.')
75 """This function reshares a post
79 data
= {'root_guid': self
.data
['guid'],
80 'authenticity_token': self
._client
.get_token()}
82 r
= self
._client
.session
.post(self
._client
.pod
+
85 headers
={'accept': 'application/json'})
87 if r
.status_code
!= 201:
88 raise Exception(str(r
.status_code
) +
89 ': Post could not be reshared.')
93 def comment(self
, text
):
94 """This function comments on a post
96 :param post_id: id of the post to comment on.
98 :param text: text to comment.
103 data
= {'text': text
,
104 'authenticity_token': self
._client
.get_token()}
106 r
= self
._client
.session
.post(self
._client
.pod
+
108 str(self
.data
['id']) +
111 headers
={'accept': 'application/json'})
113 if r
.status_code
!= 201:
114 raise Exception(str(r
.status_code
) +
115 ': Comment could not be posted.')
119 def rmcomment(self
, comment_id
):
120 """This function removes a comment from a post
122 :param post_id: id of the post to remove the like from.
124 :param like_id: id of the like to remove.
129 data
= {'authenticity_token': self
._client
.get_token()}
131 r
= self
._client
.session
.delete(self
._client
.pod
+ '/posts/' +
132 str(self
.data
['id']) +
136 headers
={'accept': 'application/json'})
138 if r
.status_code
!= 204:
139 raise Exception(str(r
.status_code
) +
140 ': Comment could not be deleted.')