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.
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 """This function retrieves data of the post.
30 r
= self
._client
.session
.get('{0}/posts/{1}.json'.format(self
._client
.pod
, self
.post_id
))
31 if r
.status_code
== 200:
34 raise Exception('wrong status code: {0}'.format(r
.status_code
))
37 """This function likes a post.
38 It abstracts the 'Like' functionality.
40 :returns: dict -- json formatted like object.
43 data
= {'authenticity_token': self
._client
.get_token()}
45 r
= self
._client
.session
.post('{0}/posts/{1}/likes'.format(self
._client
.pod
, self
.post_id
),
47 headers
={'accept': 'application/json'})
49 if r
.status_code
!= 201:
50 raise Exception('{0}: Post could not be liked.'.format(r
.status_code
))
54 def delete_like(self
):
55 """This function removes a like from a post
58 data
= {'authenticity_token': self
._client
.get_token()}
60 post_data
= self
.get_data()
62 r
= self
._client
.session
.delete('{0}/posts/{1}/likes/{2}'.format(self
._client
.pod
, self
.post_id
, post_data
['interactions']['likes'][0]['id']),
65 if r
.status_code
!= 204:
66 raise Exception('{0}: Like could not be removed.'.format(r
.status_code
))
69 """This function reshares a post
72 post_data
= self
.get_data()
74 data
= {'root_guid': post_data
['guid'],
75 'authenticity_token': self
._client
.get_token()}
77 r
= self
._client
.session
.post('{0}/reshares'.format(self
._client
.pod
),
79 headers
={'accept': 'application/json'})
81 if r
.status_code
!= 201:
82 raise Exception('{0}: Post could not be reshared.'.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'.format(self
._client
.pod
, self
.post_id
),
98 headers
={'accept': 'application/json'})
100 if r
.status_code
!= 201:
101 raise Exception('{0}: Comment could not be posted.'.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}'.format(self
._client
.pod
, self
.post_id
, comment_id
),
116 headers
={'accept': 'application/json'})
118 if r
.status_code
!= 204:
119 raise Exception('{0}: Comment could not be deleted.'.format(r
.status_code
))
122 """ This function deletes this post
125 data
= {'authenticity_token': self
._client
.get_token()}
127 r
= self
._client
.session
.delete('{0}/posts/{1}'.format(self
._client
.pod
, self
.post_id
),
129 headers
={'accept': 'application/json'})