photos: Implement more generic folder fetching
Preparation for photo service update/refresh functionality.
This commit is contained in:
parent
1e53077ab9
commit
2d541a9681
1 changed files with 22 additions and 6 deletions
|
@ -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']
|
||||
|
|
Loading…
Reference in a new issue