:type username: str
:param password: The password used to log in.
:type password: str
--
"""
self._token_regex = re.compile(r'content="(.*?)"\s+name="csrf-token')
self.pod = pod
self.session = requests.Session()
- self._post_data = None
+ self._post_data = {}
self._setlogindata(username, password)
+ self._login()
def get_token(self):
"""This function gets a token needed for authentication in most cases
headers={'accept': 'application/json'})
if r.status_code != 201: raise Exception('{0}: Login failed.'.format(r.status_code))
-
+
- def _set_post_data(self, text, aspect_id, photos):
- """This method prepares data for post.
-
+ def _setpostdata(self, text, aspect_id, photos):
+ """This function prepares data for posting.
+
:param text: Text to post.
:type text: str
:param aspect_id: Aspect id to send post to.
:type aspect_id: str
:returns: diaspy.models.Post -- the Post which has been created
--
"""
- self._set_post_data(text, aspect_id, photos)
- r = self.session.post('{0}/status_messages'.format(self.pod),
- data=json.dumps(self._post_data),
- headers={'content-type': 'application/json',
- 'accept': 'application/json',
- 'x-csrf-token': self.get_token()})
- if r.status_code != 201: raise Exception('{0}: Post could not be posted.'.format(r.status_code))
-
- return diaspy.models.Post(str(r.json()['id']), self)
+ self._setpostdata(text, aspect_id, photos)
- return self._post()
++ post = self._post()
++ self._post_data = {}
++ return post
def get_user_info(self):
"""This function returns the current user's attributes.