diff --git a/base.py b/base.py index 612bbc0..10de085 100644 --- a/base.py +++ b/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) diff --git a/services/calendar.py b/services/calendar.py index b7e893b..21e29b2 100644 --- a/services/calendar.py +++ b/services/calendar.py @@ -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', diff --git a/services/findmyiphone.py b/services/findmyiphone.py index 759f771..3be69ff 100644 --- a/services/findmyiphone.py +++ b/services/findmyiphone.py @@ -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']: