def calendar_list_insert(self, model_calendar_list): """ Adds an entry to the user's calendar list. :param model_calendar_list<CalendarListModel> :return: response, model<CalendarListModel> """ log_info("Send post request\nCalendarID = [{calendar_id}]".format( calendar_id=model_calendar_list.cal_id)) body = { "id": model_calendar_list.cal_id, "defaultReminders": model_calendar_list.default_reminders, "notificationSettings": model_calendar_list.notification_settings, "summaryOverride": model_calendar_list.summary_override, "colorId": model_calendar_list.color_id } http = HttpLib(url=self.url, json=body) http.auth_to_google(client=client, scope=scope_calendar) request = http.send_post() response_json = request.get_response_json(request.response) model = CalendarListModel().pars_response_to_model(response_json) log_info( "Returned:\nResponse:\n{response}\nModel calendarList:\n{model}". format(response=create_string_from_json(response_json), model=model)) return request.response, model
def update_event(self, calendar_id, event_id, new_event, client_id=client, send_notifications="False"): url = "{host}/{api}/calendars/{calendar_id}/events/{event_id}".\ format(host=self.host, api=self.api, calendar_id=calendar_id, event_id=event_id) params = {"sendNotifications": send_notifications} request_body = create_string_from_json({ "end": new_event.end, "start": new_event.start, "attendees": new_event.attendees, "iCalUID": new_event.iCalUID }) req = HttpLib(url=url, header=self.header, json=create_json_from_string(request_body), params=params) req.auth_to_google(client=client_id, scope=scope_calendar) req.send_put() if req.get_response_status_code(req.response) is status_code_200: return req.response, EventModel().get_event_model_from_json( **req.get_response_json(req.response)) return req.response, None
def pars_response_to_model(self, response_json): try: self.cal_id = response_json['id'] self.color_id = response_json['colorId'] except: assert False, "Failed pars json to filters model\nResponse:\n{response}".\ format(response=create_string_from_json(response_json)) self.default_reminders = response_json['defaultReminders'] \ if response_json.keys().count('defaultReminders') else None self.notification_settings = response_json['notificationSettings'] \ if response_json.keys().count('notificationSettings') else None self.summary_override = response_json['summaryOverride'] \ if response_json.keys().count('summaryOverride') else None return self
def batch_delete(user_id, messages_id_list): """ Deletes many messages by message ID Args: user_id(str): user email messages_id_list(list): list with messages id, which will be deleted """ log_info('Message list contains: ' + str(len(messages_id_list)) + ' messages') request_body = create_string_from_json({"ids": messages_id_list}) log_info("Messages will be deleted :" + request_body) response = UserMessages().batch_delete(user_id, request_body) log_info("Delete messages by ID") log_info("Assert status code for 'Batch delete'") status_code = HttpLib.get_response_status_code(response) assert (status_code == status_code_204), \ "Batch delete error: status code is {status_code}, response text is: {text}".format( status_code=status_code, text=HttpLib.get_response_text(response))
def calendar_list_get(self, calendar_id): """ Returns an entry on the user's calendar list. :param calendar_id<str> :return: response, model<CalendarListModel> """ log_info("Send get request\nCalendarID = [{calendar_id}]".format( calendar_id=calendar_id)) url = "{url}/{calendar_id}".format(url=self.url, calendar_id=calendar_id) http = HttpLib(url=url) http.auth_to_google(client=client, scope=scope_calendar) request = http.send_get() response_json = request.get_response_json(request.response) model = CalendarListModel().pars_response_to_model(response_json) log_info( "Returned:\nResponse:\n{response}\nModel calendarList:\n{model}". format(response=create_string_from_json(response_json), model=model)) return request.response, model
def calendar_list_patch(self, model_calendar_list): """ Updates an entry on the user's calendar list. This method supports patch semantics. :param model_calendar_list<CalendarListModel> :return: response, model<CalendarListModel> """ log_info("Send patch request\nCalendarID = [{calendar_id}]".format( calendar_id=model_calendar_list.cal_id)) url = "{url}/{calendar_id}".format( url=self.url, calendar_id=model_calendar_list.cal_id) body = { "defaultReminders": model_calendar_list.default_reminders, "notificationSettings": model_calendar_list.notification_settings, "summaryOverride": model_calendar_list.summary_override, "colorId": model_calendar_list.color_id } http = HttpLib(url=url, json=body) http.auth_to_google(client=client, scope=scope_calendar) request = http.send_patch() response_json = request.get_response_json(request.response) model = CalendarListModel().pars_response_to_model(response_json) log_info("Returned:\nModel calendarList:\n{model}".format( response=create_string_from_json(response_json), model=model)) return request.response, model
def __str__(self): return create_string_from_json(self.__dict__)