Merge branch 'posts' into devel
authorMarek Marecki <triviuss@gmail.com>
Fri, 29 Mar 2013 09:49:16 +0000 (10:49 +0100)
committerMarek Marecki <triviuss@gmail.com>
Fri, 29 Mar 2013 09:49:16 +0000 (10:49 +0100)
Conflicts:
diaspy/client.py

1  2 
diaspy/client.py

index 55f22eee35281b0f8ae247cd9cc2eb7970ea135c,7960eefe4e80605ddb43de4a3d3c44774769ef31..aae0681978c1d9d69c003028d9827b7b90a07889
@@@ -16,13 -16,14 +16,13 @@@ class Client
          :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.