From 2d541a9681233628e350413fab202f4379884aed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 7 Jul 2016 01:17:51 +0200 Subject: [PATCH] photos: Implement more generic folder fetching Preparation for photo service update/refresh functionality. --- pyicloud/services/photos.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/pyicloud/services/photos.py b/pyicloud/services/photos.py index e10e242..c50885c 100644 --- a/pyicloud/services/photos.py +++ b/pyicloud/services/photos.py @@ -49,14 +49,10 @@ class PhotosService(object): @property def albums(self): - request = self.session.get( - '%s/folders' % self._service_endpoint, - params=self.params - ) - response = request.json() albums = {} - for folder in response['folders']: + for folder in self._fetch_folders(): if not folder['type'] == 'album': + # FIXME: Handle subfolders continue album = PhotoAlbum(folder, self) @@ -64,6 +60,26 @@ class PhotosService(object): return albums + def _fetch_folders(self, server_ids=[]): + folders = server_ids if server_ids else "" + logger.debug("Fetching folders %s...", folders) + + data = json.dumps({ + 'syncToken': self.params.get('syncToken'), + 'methodOverride': 'GET', + 'serverIds': server_ids, + }) if server_ids else None + + method = 'POST' if data else 'GET' + request = self.session.request( + method, + '%s/folders' % self._service_endpoint, + params=self.params, + data=data + ) + response = request.json() + return response['folders'] + @property def all(self): return self.albums['All Photos']