def _login(self):
"""This function is used to connect to the pod and log in.
"""
- r = self.session.post('{0}/users/sign_in'.format(self.pod),
+ r = self._sessionpost('users/sign_in',
data=self._login_data,
headers={'accept': 'application/json'})
if r.status_code != 201:
:returns: diaspy.models.Post -- the Post which has been created
"""
- r = self.session.post('{0}/status_messages'.format(self.pod),
+ r = self._sessionpost('status_messages',
data=json.dumps(self._post_data),
headers={'content-type': 'application/json',
'accept': 'application/json',
'x-csrf-token': self.get_token(),
'x-file-name': filename}
- r = self.session.post('{0}/photos'.format(self.pod),
- params=params, data=data, headers=headers)
-
+ r = self._sessionpost('photos', params=params, data=data, headers=headers)
return r
def get_stream(self):
raise Exception('wrong status code: {0}'.format(r.status_code))
mailbox = r.json()
- return [diaspy.conversations.Conversation(str(conversation['conversation']['id']), self) for conversation in mailbox]
+ return [diaspy.conversations.Conversation(str(conversation['conversation']['id']), self)
+ for conversation in mailbox]
def add_user_to_aspect(self, user_id, aspect_id):
""" this function adds a user to an aspect.
:type aspect_id: str
"""
-
data = {'authenticity_token': self.get_token(),
'aspect_id': aspect_id,
'person_id': user_id}
- r = self.session.post('{0}/aspect_memberships.json'.format(self.pod),
- data=data)
+ r = self._sessionpost('aspect_memberships.json', data=data)
if r.status_code != 201:
raise Exception('wrong status code: {0}'.format(r.status_code))
'aspect[name]': aspect_name,
'aspect[contacts_visible]': visible}
- r = self.session.post('{0}/aspects'.format(self.pod),
- data=data)
+ r = self._sessionpost('aspects', data=data)
if r.status_code != 200:
raise Exception('wrong status code: {0}'.format(r.status_code))
if r.status_code != 404:
raise Exception('wrong status code: {0}'.format(r.status_code))
- def get_mailbox(self):
- """This functions returns a list of messages found in the conversation.
-
- :returns: list -- list of Conversation objects.
-
- """
-
- r = self.session.get('{0}/conversations.json'.format(self.pod))
-
- if r.status_code != 200:
- raise Exception('wrong status code: {0}'.format(r.status_code))
-
- mailbox = r.json()
- conversations = [diaspy.conversations.Conversation(
- str(conversation['conversation']['id']), self) for
- conversation in mailbox]
-
- return conversations
-
def new_conversation(self, contacts, subject, text):
"""Start a new conversation.
'utf8': '✓',
'authenticity_token': self.get_token()}
- r = self.session.post('{0}/conversations/'.format(self.pod),
+ r = self._sessionpost('conversations/',
data=data,
headers={'accept': 'application/json'})
if r.status_code != 200:
"""
data = {'authenticity_token': self._client.get_token()}
- r = self._client.session.post('{0}/posts/{1}/likes'
- .format(self._client.pod, self.post_id),
+ r = self._client._sessionpost('posts/{0}/likes'.format(self.post_id),
data=data,
headers={'accept': 'application/json'})
data = {'root_guid': post_data['guid'],
'authenticity_token': self._client.get_token()}
- r = self._client.session.post('{0}/reshares'.format(self._client.pod),
+ r = self._client._sessionpost('reshares',
data=data,
headers={'accept': 'application/json'})
data = {'text': text,
'authenticity_token': self._client.get_token()}
- r = self._client.session.post('{0}/posts/{1}/comments'
- .format(self._client.pod, self.post_id),
+ r = self._client._sessionpost('posts/{0}/comments'.format(self.post_id),
data=data,
headers={'accept': 'application/json'})
def delete(self):
""" This function deletes this post
-
"""
data = {'authenticity_token': self._client.get_token()}
r = self._client.session.delete('{0}/posts/{1}'.format(self._client.pod, self.post_id),
headers={'accept': 'application/json'})
if r.status_code != 204:
raise Exception('{0}: Post could not be deleted'.format(r.status_code))
-
- r = self._client.session.delete('{0}/posts/{1}'
- .format(self._client.pod,
- self.post_id),
- data=data,
- headers={'accept': 'application/json'})
- if r.status_code != 204:
- raise Exception('{0}: Post could not be deleted.'
- .format(r.status_code))