5 """This class represents a post.
8 Remember that you need to have access to the post.
10 def __init__(self
, post_id
, connection
):
12 :param post_id: id or guid of the post
14 :param connection: connection object used to authenticate
15 :type connection: connection.Connection
17 self
._connection
= connection
18 self
.post_id
= post_id
21 """Returns text of a post.
23 return self
.get_data
['text']
26 """This function retrieves data of the post.
28 r
= self
._connection
.get('posts/{0}.json'.format(self
.post_id
))
29 if r
.status_code
!= 200:
30 raise Exception('wrong status code: {0}'.format(r
.status_code
))
34 """This function likes a post.
35 It abstracts the 'Like' functionality.
37 :returns: dict -- json formatted like object.
39 data
= {'authenticity_token': self
._connection
.get_token()}
41 r
= self
._connection
.post('posts/{0}/likes'.format(self
.post_id
),
43 headers
={'accept': 'application/json'})
45 if r
.status_code
!= 201:
46 raise Exception('{0}: Post could not be liked.'
47 .format(r
.status_code
))
51 def delete_like(self
):
52 """This function removes a like from a post
54 data
= {'authenticity_token': self
._connection
.get_token()}
56 post_data
= self
.get_data()
58 r
= self
._connection
.delete('posts/{0}/likes/{1}'
60 post_data
['interactions']
64 if r
.status_code
!= 204:
65 raise Exception('{0}: Like could not be removed.'
66 .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
._connection
.get_token()}
77 r
= self
._connection
.post('reshares',
79 headers
={'accept': 'application/json'})
81 if r
.status_code
!= 201:
82 raise Exception('{0}: Post could not be reshared.'
83 .format(r
.status_code
))
87 def comment(self
, text
):
88 """This function comments on a post
90 :param text: text to comment.
94 'authenticity_token': self
._connection
.get_token()}
96 r
= self
._connection
.post('posts/{0}/comments'.format(self
.post_id
),
98 headers
={'accept': 'application/json'})
100 if r
.status_code
!= 201:
101 raise Exception('{0}: Comment could not be posted.'
102 .format(r
.status_code
))
106 def delete_comment(self
, comment_id
):
107 """This function removes a comment from a post
109 :param comment_id: id of the comment to remove.
110 :type comment_id: str
112 data
= {'authenticity_token': self
._connection
.get_token()}
114 r
= self
._connection
.delete('posts/{0}/comments/{1}'
115 .format(self
.post_id
,
118 headers
={'accept': 'application/json'})
120 if r
.status_code
!= 204:
121 raise Exception('{0}: Comment could not be deleted.'
122 .format(r
.status_code
))
125 """ This function deletes this post
127 data
= {'authenticity_token': self
._connection
.get_token()}
128 r
= self
._connection
.delete('posts/{0}'.format(self
.post_id
),
130 headers
={'accept': 'application/json'})
131 if r
.status_code
!= 204:
132 raise Exception('{0}: Post could not be deleted'.format(r
.status_code
))
136 """This class represents an aspect.
138 def __init__(self
, connection
, id=-1):
139 self
._connection
= connection
143 def addUser(self
, user_id
):
144 """Add user to current aspect.
146 :param user_id: user to add to aspect
149 data
= {'authenticity_token': self
._connection
.get_token(),
150 'aspect_id': self
.id,
151 'person_id': user_id
}
153 request
= self
._connection
.post('aspect_memberships.json', data
=data
)
155 if request
.status_code
!= 201:
156 raise Exception('wrong status code: {0}'.format(request
.status_code
))
157 return request
.json()
159 def removeUser(self
, user_id
):
160 """Remove user from current aspect.
162 :param user_id: user to remove from aspect
165 data
= {'authenticity_token': self
._connection
.get_token(),
166 'aspect_id': self
.id,
167 'person_id': user_id
}
169 request
= self
.connection
.delete('aspect_memberships/42.json', data
=data
)
171 if request
.status_code
!= 200:
172 raise Exception('wrong status code: {0}'.format(request
.status_code
))
173 return request
.json()