Esempio n. 1
0
 def _operation(self, type, operation, from_path, to_path, filename, exists='rename'):
     url = '{0}{1}/'.format(BASEURL, type)
     params = {
         'access_token': self.access_token,
         'operation': operation
     }
     data = {
         'from': from_path,
         'filename': filename,
         'exists': exists
     }
     if to_path:
         data['to'] = to_path
     response = requests.post(url, params=params, data=data)
     result = json.loads(response.content)
     if response.status_code != 200:
         raise BitcasaException(result['error']['code'], result['error']['message'])
     if type == 'folders':
         new_path = result['result']['items'][0]['path']
         new_name = result['result']['items'][0]['name']
         return BitcasaFolder.folder_from_response(self, new_name, new_path, None)
     elif type == 'files':
         item = result['result']['items'][0]
         f = BitcasaFile(self, item['path'], item['name'], item['extension'], item['size'])
         return f
Esempio n. 2
0
 def create_folder(self, path, name):
     url = '{0}folders{1}'.format(BASEURL, path)
     params = {
         'access_token': self.access_token
     }
     data = {
         'folder_name': name
     }
     response = requests.post(url, params=params, data=data)
     result = json.loads(response.content)
     if response.status_code != 200:
         raise BitcasaException(result['error']['code'], result['error']['message'])
     new_path = result['result']['items'][0]['path']
     return BitcasaFolder.folder_from_response(self, name, new_path, None)
Esempio n. 3
0
    def get_folder(self, path, name='root'):
        url = '{0}folders{1}'.format(BASEURL, path)
        params = {
            'access_token': self.access_token
        }
        try:
            response = requests.get(url, params=params)
        except:
            raise BitcasaException(500, "Error with request")

        try:
            result = json.loads(response.content)
        except ValueError:
            content = response.content
            if len(content) > 2048:
                content = content[:2048]
            raise BitcasaException(response.status_code, "Failed to decode response %s" % content)


        if response.status_code != 200:
            raise BitcasaException(result['error']['code'], result['error']['message'])
        return BitcasaFolder.folder_from_response(self, name, path, result['result']['items'])