def delete_like(self): """This function removes a like from a post """ data = {'authenticity_token': repr(self._connection)} url = 'posts/{0}/likes/{1}'.format(self.id, self._data['interactions']['likes'][0]['id']) request = self._connection.delete(url, data=data) if request.status_code != 204: raise errors.PostError('{0}: Like could not be removed.' .format(request.status_code))
def delete(self): """ This function deletes this post """ data = {'authenticity_token': repr(self._connection)} request = self._connection.delete('posts/{0}'.format(self.id), data=data, headers={'accept': 'application/json'}) if request.status_code != 204: raise errors.PostError('{0}: Post could not be deleted'.format(request.status_code))
def _fetchcomments(self): """Retreives comments for this post. Retrieving comments via GUID will result in 404 error. DIASPORA* does not supply comments through /posts/:guid/ endpoint. """ id = self._data['id'] if self['interactions']['comments_count']: request = self._connection.get('posts/{0}/comments.json'.format(id)) if request.status_code != 200: raise errors.PostError('{0}: could not fetch comments for post: {1}'.format(request.status_code, id)) else: self.comments = [Comment(c) for c in request.json()]
def _fetchdata(self): """This function retrieves data of the post. :returns: guid of post whose data was fetched """ if self.id: id = self.id if self.guid: id = self.guid request = self._connection.get('posts/{0}.json'.format(id)) if request.status_code != 200: raise errors.PostError('{0}: could not fetch data for post: {1}'.format(request.status_code, id)) else: self._data = request.json() return self['guid']
def _fetchcomments(self): """Retreives comments for this post. """ if self.id: id = self.id if self.guid: id = self.guid if self['interactions']['comments_count']: request = self._connection.get( 'posts/{0}/comments.json'.format(id)) if request.status_code != 200: raise errors.PostError( '{0}: could not fetch comments for post: {1}'.format( request.status_code, id)) else: self.comments = [Comment(c) for c in request.json()]
def delete_comment(self, comment_id): """This function removes a comment from a post :param comment_id: id of the comment to remove. :type comment_id: str """ data = {'authenticity_token': repr(self._connection)} request = self._connection.delete( 'posts/{0}/comments/{1}'.format(self.id, comment_id), data=data, headers={'accept': 'application/json'}) if request.status_code != 204: raise errors.PostError('{0}: Comment could not be deleted'.format( request.status_code))
def like(self): """This function likes a post. It abstracts the 'Like' functionality. :returns: dict -- json formatted like object. """ data = {'authenticity_token': repr(self._connection)} request = self._connection.post('posts/{0}/likes'.format(self.id), data=data, headers={'accept': 'application/json'}) if request.status_code != 201: raise errors.PostError('{0}: Post could not be liked.'.format( request.status_code)) return request.json()