34a675b9bde1e1d5dcc3f88415611e4324eda606
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
, client
):
13 :param post_id: id or guid of the post
15 :param client: client object used to authenticate
16 :type client: client.Client
19 self
.post_id
= post_id
22 """This function retrieves data of the post.
24 r
= self
._client
._sessionget
('posts/{1}.json'.format(self
.post_id
))
25 if r
.status_code
== 200:
28 raise Exception('wrong status code: {0}'.format(r
.status_code
))
31 """This function likes a post.
32 It abstracts the 'Like' functionality.
34 :returns: dict -- json formatted like object.
36 data
= {'authenticity_token': self
._client
.get_token()}
38 r
= self
._client
.session
.post('{0}/posts/{1}/likes'
39 .format(self
._client
.pod
, self
.post_id
),
41 headers
={'accept': 'application/json'})
43 if r
.status_code
!= 201:
44 raise Exception('{0}: Post could not be liked.'
45 .format(r
.status_code
))
49 def delete_like(self
):
50 """This function removes a like from a post
52 data
= {'authenticity_token': self
._client
.get_token()}
54 post_data
= self
.get_data()
56 r
= self
._client
.session
.delete('{0}/posts/{1}/likes/{2}'
57 .format(self
._client
.pod
,
59 post_data
['interactions']
63 if r
.status_code
!= 204:
64 raise Exception('{0}: Like could not be removed.'
65 .format(r
.status_code
))
68 """This function reshares a post
71 post_data
= self
.get_data()
73 data
= {'root_guid': post_data
['guid'],
74 'authenticity_token': self
._client
.get_token()}
76 r
= self
._client
.session
.post('{0}/reshares'.format(self
._client
.pod
),
78 headers
={'accept': 'application/json'})
80 if r
.status_code
!= 201:
81 raise Exception('{0}: Post could not be reshared.'
82 .format(r
.status_code
))
86 def comment(self
, text
):
87 """This function comments on a post
89 :param text: text to comment.
94 'authenticity_token': self
._client
.get_token()}
96 r
= self
._client
.session
.post('{0}/posts/{1}/comments'
97 .format(self
._client
.pod
, self
.post_id
),
99 headers
={'accept': 'application/json'})
101 if r
.status_code
!= 201:
102 raise Exception('{0}: Comment could not be posted.'
103 .format(r
.status_code
))
107 def delete_comment(self
, comment_id
):
108 """This function removes a comment from a post
110 :param comment_id: id of the comment to remove.
111 :type comment_id: str
114 data
= {'authenticity_token': self
._client
.get_token()}
116 r
= self
._client
.session
.delete('{0}/posts/{1}/comments/{2}'
117 .format(self
._client
.pod
,
121 headers
={'accept': 'application/json'})
123 if r
.status_code
!= 204:
124 raise Exception('{0}: Comment could not be deleted.'
125 .format(r
.status_code
))
128 """ This function deletes this post
131 data
= {'authenticity_token': self
._client
.get_token()}
132 r
= self
._client
.session
.delete('{0}/posts/{1}'.format(self
._client
.pod
, self
.post_id
),
134 headers
={'accept': 'application/json'})
135 if r
.status_code
!= 204:
136 raise Exception('{0}: Post could not be deleted'.format(r
.status_code
))
138 r
= self
._client
.session
.delete('{0}/posts/{1}'
139 .format(self
._client
.pod
,
142 headers
={'accept': 'application/json'})
143 if r
.status_code
!= 204:
144 raise Exception('{0}: Post could not be deleted.'
145 .format(r
.status_code
))