diff --git a/pyicloud/base.py b/pyicloud/base.py index fcf2982..bed32d6 100644 --- a/pyicloud/base.py +++ b/pyicloud/base.py @@ -21,7 +21,8 @@ from pyicloud.services import ( UbiquityService, ContactsService, RemindersService, - PhotosService + PhotosService, + AccountService ) from pyicloud.utils import get_password_from_keyring @@ -269,6 +270,15 @@ class PyiCloudService(object): self.params ) + @property + def account(self): + service_root = self.webservices['account']['url'] + return AccountService( + service_root, + self.session, + self.params + ) + @property def iphone(self): return self.devices[0] diff --git a/pyicloud/services/__init__.py b/pyicloud/services/__init__.py index 9a72d59..cf51661 100644 --- a/pyicloud/services/__init__.py +++ b/pyicloud/services/__init__.py @@ -4,3 +4,4 @@ from pyicloud.services.ubiquity import UbiquityService from pyicloud.services.contacts import ContactsService from pyicloud.services.reminders import RemindersService from pyicloud.services.photos import PhotosService +from pyicloud.services.account import AccountService diff --git a/pyicloud/services/account.py b/pyicloud/services/account.py new file mode 100644 index 0000000..ddf8392 --- /dev/null +++ b/pyicloud/services/account.py @@ -0,0 +1,39 @@ +import sys + + +class AccountService(object): + def __init__(self, service_root, session, params): + self.session = session + self.params = params + self._service_root = service_root + self._devices = [] + + self._acc_endpoint = '%s/setup/web/device' % self._service_root + self._account_devices_url = '%s/getDevices' % self._acc_endpoint + + req = self.session.get(self._account_devices_url, params=self.params) + self.response = req.json() + + for device_info in self.response['devices']: + # device_id = device_info['udid'] + # self._devices[device_id] = AccountDevice(device_info) + self._devices.append(AccountDevice(device_info)) + + @property + def devices(self): + return self._devices + + +class AccountDevice(object): + def __init__(self, device_info): + self.serialNumber = device_info['serialNumber'] + self.osVersion = device_info['osVersion'] + self.modelLargePhotoURL2x = device_info['modelLargePhotoURL2x'] + self.modelLargePhotoURL1x = device_info['modelLargePhotoURL1x'] + self.name = device_info['name'] + self.imei = device_info['imei'] + self.model = device_info['model'] + self.udid = device_info['udid'] + self.modelSmallPhotoURL2x = device_info['modelSmallPhotoURL2x'] + self.modelSmallPhotoURL1x = device_info['modelSmallPhotoURL1x'] + self.modelDisplayName = device_info['modelDisplayName']