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
._sessionpost
('posts/{0}/likes'.format(self
.post_id
),
40 headers
={'accept': 'application/json'})
42 if r
.status_code
!= 201:
43 raise Exception('{0}: Post could not be liked.'
44 .format(r
.status_code
))
48 def delete_like(self
):
49 """This function removes a like from a post
51 data
= {'authenticity_token': self
._client
.get_token()}
53 post_data
= self
.get_data()
55 r
= self
._client
.session
.delete('{0}/posts/{1}/likes/{2}'
56 .format(self
._client
.pod
,
58 post_data
['interactions']
62 if r
.status_code
!= 204:
63 raise Exception('{0}: Like could not be removed.'
64 .format(r
.status_code
))
67 """This function reshares a post
70 post_data
= self
.get_data()
72 data
= {'root_guid': post_data
['guid'],
73 'authenticity_token': self
._client
.get_token()}
75 r
= self
._client
._sessionpost
('reshares',
77 headers
={'accept': 'application/json'})
79 if r
.status_code
!= 201:
80 raise Exception('{0}: Post could not be reshared.'
81 .format(r
.status_code
))
85 def comment(self
, text
):
86 """This function comments on a post
88 :param text: text to comment.
93 'authenticity_token': self
._client
.get_token()}
95 r
= self
._client
._sessionpost
('posts/{0}/comments'.format(self
.post_id
),
97 headers
={'accept': 'application/json'})
99 if r
.status_code
!= 201:
100 raise Exception('{0}: Comment could not be posted.'
101 .format(r
.status_code
))
105 def delete_comment(self
, comment_id
):
106 """This function removes a comment from a post
108 :param comment_id: id of the comment to remove.
109 :type comment_id: str
112 data
= {'authenticity_token': self
._client
.get_token()}
114 r
= self
._client
.session
.delete('{0}/posts/{1}/comments/{2}'
115 .format(self
._client
.pod
,
119 headers
={'accept': 'application/json'})
121 if r
.status_code
!= 204:
122 raise Exception('{0}: Comment could not be deleted.'
123 .format(r
.status_code
))
126 """ This function deletes this post
128 data
= {'authenticity_token': self
._client
.get_token()}
129 r
= self
._client
.session
.delete('{0}/posts/{1}'.format(self
._client
.pod
, self
.post_id
),
131 headers
={'accept': 'application/json'})
132 if r
.status_code
!= 204:
133 raise Exception('{0}: Post could not be deleted'.format(r
.status_code
))