Merge pull request #57 from torarnv/various-cleanup-fixes
Various cleanup fixes
This commit is contained in:
commit
c0a597986e
6 changed files with 11 additions and 26 deletions
16
README.rst
16
README.rst
|
@ -15,18 +15,18 @@ At its core, PyiCloud connects to iCloud using your username and password, then
|
|||
Authentication
|
||||
==============
|
||||
|
||||
Authentication is as simple as passing your username and password to the `PyiCloudService` class:
|
||||
Authentication is as simple as passing your username and password to the ``PyiCloudService`` class:
|
||||
|
||||
>>> from pyicloud import PyiCloudService
|
||||
>>> api = PyiCloudService('jappleseed@apple.com', 'password')
|
||||
|
||||
In the event that the username/password combination is invalid, a `PyiCloudFailedLoginException` exception is thrown.
|
||||
In the event that the username/password combination is invalid, a ``PyiCloudFailedLoginException`` exception is thrown.
|
||||
|
||||
=======
|
||||
Devices
|
||||
=======
|
||||
|
||||
You can list which devices associated with your account by using the `devices` property:
|
||||
You can list which devices associated with your account by using the ``devices`` property:
|
||||
|
||||
>>> api.devices
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ and you can access individual devices by either their index, or their ID:
|
|||
>>> api.devices['i9vbKRGIcLYqJnXMd1b257kUWnoyEBcEh6yM+IfmiMLh7BmOpALS+w==']
|
||||
<AppleDevice(iPhone 4S: Johnny Appleseed's iPhone)>
|
||||
|
||||
or, as a shorthand if you have only one associated apple device, you can simply use the `iphone` property to access the first device associated with your account:
|
||||
or, as a shorthand if you have only one associated apple device, you can simply use the ``iphone`` property to access the first device associated with your account:
|
||||
|
||||
>>> api.iphone
|
||||
<AppleDevice(iPhone 4S: Johnny Appleseed's iPhone)>
|
||||
|
@ -134,7 +134,7 @@ Note: These contacts do not include contacts federated from e.g. Facebook, only
|
|||
File Storage (Ubiquity)
|
||||
=======================
|
||||
|
||||
You can access documents stored in your iCloud account by using the `files` property's `dir` method:
|
||||
You can access documents stored in your iCloud account by using the ``files`` property's ``dir`` method:
|
||||
|
||||
>>> api.files.dir()
|
||||
[u'.do-not-delete',
|
||||
|
@ -165,12 +165,12 @@ datetime.datetime(2012, 9, 13, 2, 26, 17)
|
|||
>>> api.files['com~apple~Notes']['Documents']['Some Document'].type
|
||||
u'file'
|
||||
|
||||
And when you have a file that you'd like to download, the `open` method will return a response object from which you can read the `content`.
|
||||
And when you have a file that you'd like to download, the ``open`` method will return a response object from which you can read the ``content``.
|
||||
|
||||
>>> api.files['com~apple~Notes']['Documents']['Some Document'].open().content
|
||||
'Hello, these are the file contents'
|
||||
|
||||
Note: the object returned from the above `open` method is a `response object <http://www.python-requests.org/en/latest/api/#classes>`_ and the `open` method can accept any parameters you might normally use in a request using `requests <https://github.com/kennethreitz/requests>`_.
|
||||
Note: the object returned from the above ``open`` method is a `response object <http://www.python-requests.org/en/latest/api/#classes>`_ and the ``open`` method can accept any parameters you might normally use in a request using `requests <https://github.com/kennethreitz/requests>`_.
|
||||
|
||||
For example, if you know that the file you're opening has JSON content:
|
||||
|
||||
|
@ -179,7 +179,7 @@ For example, if you know that the file you're opening has JSON content:
|
|||
>>> api.files['com~apple~Notes']['Documents']['information.json'].open().json()['How much we love you']
|
||||
'lots'
|
||||
|
||||
Or, if you're downloading a particularly large file, you may want to use the `stream` keyword argument, and read directly from the raw response object:
|
||||
Or, if you're downloading a particularly large file, you may want to use the ``stream`` keyword argument, and read directly from the raw response object:
|
||||
|
||||
>>> download = api.files['com~apple~Notes']['Documents']['big_file.zip'].open(stream=True)
|
||||
>>> with open('downloaded_file.zip', 'wb') as opened_file:
|
||||
|
|
|
@ -40,13 +40,10 @@ class PyiCloudService(object):
|
|||
self.user = {'apple_id': apple_id, 'password': password}
|
||||
|
||||
self._home_endpoint = 'https://www.icloud.com'
|
||||
self._setup_endpoint = 'https://p12-setup.icloud.com/setup/ws/1'
|
||||
self._push_endpoint = 'https://p12-pushws.icloud.com'
|
||||
self._setup_endpoint = 'https://setup.icloud.com/setup/ws/1'
|
||||
|
||||
self._base_login_url = '%s/login' % self._setup_endpoint
|
||||
self._base_validate_url = '%s/validate' % self._setup_endpoint
|
||||
self._base_system_url = '%s/system/version.json' % self._home_endpoint
|
||||
self._base_webauth_url = '%s/refreshWebAuth' % self._push_endpoint
|
||||
|
||||
if cookie_directory:
|
||||
self._cookie_directory = os.path.expanduser(
|
||||
|
@ -61,9 +58,8 @@ class PyiCloudService(object):
|
|||
self.session = requests.Session()
|
||||
self.session.verify = verify
|
||||
self.session.headers.update({
|
||||
'host': 'setup.icloud.com',
|
||||
'origin': self._home_endpoint,
|
||||
'referer': '%s/' % self._home_endpoint,
|
||||
'Origin': self._home_endpoint,
|
||||
'Referer': '%s/' % self._home_endpoint,
|
||||
'User-Agent': 'Opera/9.52 (X11; Linux i686; U; en)'
|
||||
})
|
||||
|
||||
|
|
|
@ -57,8 +57,6 @@ class CalendarService(object):
|
|||
Fetches a single event's details by specifying a pguid
|
||||
(a calendar) and a guid (an event's ID).
|
||||
"""
|
||||
host = self._service_root.split('//')[1].split(':')[0]
|
||||
self.session.headers.update({'host': host})
|
||||
params = dict(self.params)
|
||||
params.update({'lang': 'en-us', 'usertz': self.get_system_tz()})
|
||||
url = '%s/%s/%s' % (self._calendar_event_detail_url, pguid, guid)
|
||||
|
@ -78,8 +76,6 @@ class CalendarService(object):
|
|||
from_dt = datetime(today.year, today.month, first_day)
|
||||
if not to_dt:
|
||||
to_dt = datetime(today.year, today.month, last_day)
|
||||
host = self._service_root.split('//')[1].split(':')[0]
|
||||
self.session.headers.update({'host': host})
|
||||
params = dict(self.params)
|
||||
params.update({
|
||||
'lang': 'en-us',
|
||||
|
|
|
@ -22,8 +22,6 @@ class ContactsService(object):
|
|||
Refreshes the ContactsService endpoint, ensuring that the
|
||||
contacts data is up-to-date.
|
||||
"""
|
||||
host = self._service_root.split('//')[1].split(':')[0]
|
||||
self.session.headers.update({'host': host})
|
||||
params_contacts = dict(self.params)
|
||||
params_contacts.update({
|
||||
'clientVersion': '2.1',
|
||||
|
|
|
@ -33,8 +33,6 @@ class FindMyiPhoneServiceManager(object):
|
|||
This ensures that the location data is up-to-date.
|
||||
|
||||
"""
|
||||
host = self._service_root.split('//')[1].split(':')[0]
|
||||
self.session.headers.update({'host': host})
|
||||
req = self.session.post(
|
||||
self._fmip_refresh_url,
|
||||
params=self.params,
|
||||
|
|
|
@ -13,9 +13,6 @@ class UbiquityService(object):
|
|||
self._service_root = service_root
|
||||
self._node_url = '/ws/%s/%s/%s'
|
||||
|
||||
host = self._service_root.split('//')[1].split(':')[0]
|
||||
self.session.headers.update({'host': host})
|
||||
|
||||
def get_node_url(self, id, variant='item'):
|
||||
return self._service_root + self._node_url % (
|
||||
self.params['dsid'],
|
||||
|
|
Loading…
Reference in a new issue