Instead of hard setting the web service URI in each Service class, re-use the service root URI we receive from the login response.
This commit is contained in:
parent
93a2d9cd79
commit
5930e27188
3 changed files with 15 additions and 9 deletions
7
base.py
7
base.py
|
@ -97,11 +97,14 @@ class PyiCloudService(object):
|
|||
self.refresh_validate()
|
||||
|
||||
self.discovery = req.json()
|
||||
self.webservices = self.discovery['webservices']
|
||||
|
||||
@property
|
||||
def iphone(self):
|
||||
return FindMyiPhoneService(self.session, self.params)
|
||||
service_root = self.webservices['findme']['url']
|
||||
return FindMyiPhoneService(service_root, self.session, self.params)
|
||||
|
||||
@property
|
||||
def calendar(self):
|
||||
return CalendarService(self.session, self.params)
|
||||
service_root = self.webservices['calendar']['url']
|
||||
return CalendarService(service_root, self.session, self.params)
|
||||
|
|
|
@ -8,10 +8,11 @@ class CalendarService(object):
|
|||
"""
|
||||
The 'Calendar' iCloud service, connects to iCloud and returns events.
|
||||
"""
|
||||
def __init__(self, session, params):
|
||||
def __init__(self, service_root, session, params):
|
||||
self.session = session
|
||||
self.params = params
|
||||
self._calendar_endpoint = 'https://p12-calendarws.icloud.com/ca'
|
||||
self._service_root = service_root
|
||||
self._calendar_endpoint = '%s/ca' % self._service_root
|
||||
self._calendar_refresh_url = '%s/events' % self._calendar_endpoint
|
||||
|
||||
def get_system_tz(self):
|
||||
|
@ -33,7 +34,8 @@ 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)
|
||||
self.session.headers.update({'host': 'p12-calendarws.icloud.com'})
|
||||
host = self._service_root.split('//')[1].split(':')[0]
|
||||
self.session.headers.update({'host': host})
|
||||
params = dict(self.params)
|
||||
params.update({
|
||||
'lang': 'en-us',
|
||||
|
|
|
@ -8,11 +8,11 @@ class FindMyiPhoneService(object):
|
|||
The 'Find my iPhone' iCloud service, connects to iCloud and returns
|
||||
phone data including the near-realtime latitude and longitude.
|
||||
"""
|
||||
def __init__(self, session, params):
|
||||
def __init__(self, service_root, session, params):
|
||||
self.session = session
|
||||
self.params = params
|
||||
self._fmip_root = 'https://p12-fmipweb.icloud.com'
|
||||
self._fmip_endpoint = '%s/fmipservice/client/web' % self._fmip_root
|
||||
self._service_root = service_root
|
||||
self._fmip_endpoint = '%s/fmipservice/client/web' % self._service_root
|
||||
self._fmip_refresh_url = '%s/refreshClient' % self._fmip_endpoint
|
||||
self._fmip_sound_url = '%s/playSound' % self._fmip_endpoint
|
||||
|
||||
|
@ -21,7 +21,8 @@ class FindMyiPhoneService(object):
|
|||
Refreshes the FindMyiPhoneService endpoint,
|
||||
ensuring that the location data is up-to-date.
|
||||
"""
|
||||
self.session.headers.update({'host': 'p12-fmipweb.icloud.com'})
|
||||
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)
|
||||
self.response = req.json()
|
||||
if self.response['content']:
|
||||
|
|
Loading…
Reference in a new issue