def list_reminders(self, num_reminders: int) -> Union[List[Reminder], None]: """ returns a list of the last num_reminders created reminders, or None if an error occurred """ response, content = self.auth_http.request( uri=URIs['list'], method='POST', body=client_utils.list_req_body(num_reminders=num_reminders), headers=HEADERS, ) if response.status == HTTP_OK: content_dict = json.loads(content.decode('utf-8')) if '1' not in content_dict: return [] reminders_dict_list = content_dict['1'] reminders = [ client_utils.build_reminder(reminder_dict) for reminder_dict in reminders_dict_list ] return reminders else: self._report_error(response, content, 'list_reminders') return None
def get_reminder(self, reminder_id: str) -> Optional[Reminder]: """ retrieve information about the reminder with the given id. None if an error occurred """ response, content = self.auth_http.request( uri=URIs['get'], method='POST', body=client_utils.get_req_body(reminder_id), headers=HEADERS, ) if response.status == HTTP_OK: content_dict = json.loads(content.decode('utf-8')) if content_dict == {}: print(f'Couldn\'t find reminder with id={reminder_id}') return None reminder_dict = content_dict['1'][0] return client_utils.build_reminder(reminder_dict=reminder_dict) else: self._report_error(response, content, 'get_reminder')