photos: Implement more generic folder fetching

Preparation for photo service update/refresh functionality.
This commit is contained in:
Tor Arne Vestbø 2016-07-07 01:17:51 +02:00
parent 1e53077ab9
commit 2d541a9681

View file

@ -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']