raise PyiCloudServiceNotActivatedException if webservice is not available
This commit is contained in:
parent
01aeb8335a
commit
0d7d9e590b
3 changed files with 21 additions and 11 deletions
|
@ -234,7 +234,7 @@ class PyiCloudService(object):
|
||||||
logger.debug("Cookies saved to %s", self._get_cookiejar_path())
|
logger.debug("Cookies saved to %s", self._get_cookiejar_path())
|
||||||
|
|
||||||
self.data = resp
|
self.data = resp
|
||||||
self.webservices = self.data['webservices']
|
self._webservices = self.data['webservices']
|
||||||
|
|
||||||
logger.info("Authentication completed successfully")
|
logger.info("Authentication completed successfully")
|
||||||
logger.debug(self.params)
|
logger.debug(self.params)
|
||||||
|
@ -298,10 +298,19 @@ class PyiCloudService(object):
|
||||||
|
|
||||||
return not self.requires_2sa
|
return not self.requires_2sa
|
||||||
|
|
||||||
|
def _get_webservice_url(self, ws_key):
|
||||||
|
"""Get webservice URL, raise an exception if not exists."""
|
||||||
|
if self._webservices.get(ws_key) is None:
|
||||||
|
raise PyiCloudServiceNotActivatedException(
|
||||||
|
'Webservice not available',
|
||||||
|
ws_key
|
||||||
|
)
|
||||||
|
return self._webservices[ws_key]['url']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def devices(self):
|
def devices(self):
|
||||||
""" Return all devices."""
|
""" Return all devices."""
|
||||||
service_root = self.webservices['findme']['url']
|
service_root = self._get_webservice_url('findme')
|
||||||
return FindMyiPhoneServiceManager(
|
return FindMyiPhoneServiceManager(
|
||||||
service_root,
|
service_root,
|
||||||
self.session,
|
self.session,
|
||||||
|
@ -310,7 +319,7 @@ class PyiCloudService(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def account(self):
|
def account(self):
|
||||||
service_root = self.webservices['account']['url']
|
service_root = self._get_webservice_url('account')
|
||||||
return AccountService(
|
return AccountService(
|
||||||
service_root,
|
service_root,
|
||||||
self.session,
|
self.session,
|
||||||
|
@ -324,7 +333,7 @@ class PyiCloudService(object):
|
||||||
@property
|
@property
|
||||||
def files(self):
|
def files(self):
|
||||||
if not hasattr(self, '_files'):
|
if not hasattr(self, '_files'):
|
||||||
service_root = self.webservices['ubiquity']['url']
|
service_root = self._get_webservice_url('ubiquity')
|
||||||
self._files = UbiquityService(
|
self._files = UbiquityService(
|
||||||
service_root,
|
service_root,
|
||||||
self.session,
|
self.session,
|
||||||
|
@ -335,7 +344,7 @@ class PyiCloudService(object):
|
||||||
@property
|
@property
|
||||||
def photos(self):
|
def photos(self):
|
||||||
if not hasattr(self, '_photos'):
|
if not hasattr(self, '_photos'):
|
||||||
service_root = self.webservices['ckdatabasews']['url']
|
service_root = self._get_webservice_url('ckdatabasews')
|
||||||
self._photos = PhotosService(
|
self._photos = PhotosService(
|
||||||
service_root,
|
service_root,
|
||||||
self.session,
|
self.session,
|
||||||
|
@ -345,17 +354,17 @@ class PyiCloudService(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def calendar(self):
|
def calendar(self):
|
||||||
service_root = self.webservices['calendar']['url']
|
service_root = self._get_webservice_url('calendar')
|
||||||
return CalendarService(service_root, self.session, self.params)
|
return CalendarService(service_root, self.session, self.params)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def contacts(self):
|
def contacts(self):
|
||||||
service_root = self.webservices['contacts']['url']
|
service_root = self._get_webservice_url('contacts')
|
||||||
return ContactsService(service_root, self.session, self.params)
|
return ContactsService(service_root, self.session, self.params)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def reminders(self):
|
def reminders(self):
|
||||||
service_root = self.webservices['reminders']['url']
|
service_root = self._get_webservice_url('reminders')
|
||||||
return RemindersService(service_root, self.session, self.params)
|
return RemindersService(service_root, self.session, self.params)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
|
|
|
@ -5,7 +5,7 @@ class PyiCloudException(Exception):
|
||||||
|
|
||||||
# API
|
# API
|
||||||
class PyiCloudAPIResponseException(PyiCloudException):
|
class PyiCloudAPIResponseException(PyiCloudException):
|
||||||
def __init__(self, reason, code, retry=False):
|
def __init__(self, reason, code=None, retry=False):
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
self.code = code
|
self.code = code
|
||||||
message = reason or ""
|
message = reason or ""
|
||||||
|
|
|
@ -160,8 +160,9 @@ class PhotosService(object):
|
||||||
indexing_state = response['records'][0]['fields']['state']['value']
|
indexing_state = response['records'][0]['fields']['state']['value']
|
||||||
if indexing_state != 'FINISHED':
|
if indexing_state != 'FINISHED':
|
||||||
raise PyiCloudServiceNotActivatedException(
|
raise PyiCloudServiceNotActivatedException(
|
||||||
('iCloud Photo Library not finished indexing. Please try '
|
'iCloud Photo Library not finished indexing. '
|
||||||
'again in a few minutes'), None)
|
'Please try again in a few minutes.'
|
||||||
|
)
|
||||||
|
|
||||||
# TODO: Does syncToken ever change?
|
# TODO: Does syncToken ever change?
|
||||||
# self.params.update({
|
# self.params.update({
|
||||||
|
|
Loading…
Reference in a new issue