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 update(self, user_id, label_id, label_model): """ Updates the specified label. :param label_id: the ID of the label to update. :param user_id: the user's email address. :param label_model: (LabelModel) model :return: response, (LabelModel) model """ log_info( "[Users.labels]: Updates the label with id: {label_id}".format( label_id=label_id)) url = '{host}/{api}/{user_id}/labels/{label_id}'.format( host=self.host, api=self.api, user_id=user_id, label_id=label_id) body = { "name": label_model.name, "labelListVisibility": label_model.label_list_visibility, "messageListVisibility": label_model.message_list_visibility } http = HttpLib(url=url, json=body) http.auth_to_google(client=client, scope=scope_labels) http.send_put() response_json = http.get_response_json(http.response) label_model = LabelModel().parse_response_to_model(response_json) log_info( '[Users.labels]: UPDATE response: {status_code}, \n{model}'.format( status_code=http.get_response_status_code(http.response), model=label_model)) return http.response, label_model
def update_send_as(self, user_id, send_as_email, json_body): """ Update the specified send-as alias Args: user_id (str): user id send_as_email (str): The send-as alias to be retrieved. json_body (dict): Json for patching Send As Returns: response (requests.Response) """ url = self.__get_send_as_url(user_id)+"/{send_as_email}".format(send_as_email=send_as_email) api = HttpLib(url=url, json=json_body) api.auth_to_google(client=client, scope=scope_gmail_settings) api.send_put() return api.response
def calendar_list_update(self, calendar_id, model_calendar_list): """ Updates an entry on the user's calendar list. :param calendar_id<str> :param model_calendar_list<CalendarListModel> :return: response, model<CalendarListModel> """ log_info("Send put request\nCalendarID = [{calendar_id}]".format( calendar_id=calendar_id)) url = "{url}/{calendar_id}".format(url=self.url, calendar_id=calendar_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_put() response = request.response response_json = request.get_response_json(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 response, model
def update(self, json_data, rule_id): """ Метод отпрвляет PUT запрос для обновления правила календаря Returns: response (requests.Response): ответ от сервера """ http = HttpLib( url="{host}/{api}/calendars/{calendar_id}/acl/{rule_id}".format( host=self.host, api=self.api, calendar_id=self.calendar_id, rule_id=rule_id), json=json_data) http.auth_to_google(client=client, scope=scope_calendar) http.send_put() return http.response
def update_imap(self, imap_model, user_id="me", oauth_client=client): """ Send put request to Users.settings: getVacation :param imap_model: Imap Model object :param user_id: user email address for request :param oauth_client: client that should be authorized with oauth 2.0 :return: response and status code """ url = "{host}/{api}/{service}".format( host=self.host, api=self.api, service=url_getImap.format(userId=user_id)) log_info("Update imap url is: {url}".format(url=url)) body = imap_model.create_json_from_model() http = HttpLib(url, json=body) http.auth_to_google(client=oauth_client, scope=scope_gmail_setting) http.send_put() log_pretty_json(http.get_response_json(http.response), "Update imap response") return http.get_response_json( http.response), http.get_response_status_code(http.response)
def update_draft(self, user_id, draft_message_id, raw_txt): """ Args: user_id (str): user id draft_message_id (str): draft message id in the draft raw_txt (str): string in the base64 format Returns: api.response (requests.Response): response from the server model (MessageModel): the model is getting from the server """ url = self.__get_message_url(user_id=user_id, draft_message_id=draft_message_id) json_update = {"id": draft_message_id, "message": {"raw": raw_txt}} api = HttpLib(url=url, header=self.header, json=json_update) api.auth_to_google(client=client, scope=scope_mail) api.send_put() model = MessageModel().get_draft_message_model_from_json( api.get_response_json(api.response)) return api.response, model
def update_calendar(self, calendar_model_output, calendar_model_initial): """ Update calendar. This operation update calendar in the primary calendar of an account. :param calendar_model_output calendar_model_initial :return: response """ log_info("Update calendar...") json_update = CalendarsModel().create_json_for_request(calendar_model_initial.summary, calendar_model_initial.description, calendar_model_initial.location) url = self.host + '/{calendar_id}'.format(calendar_id=calendar_model_output.id) http = HttpLib(url=url, json=json_update) http.auth_to_google(client=client, scope=scope_calendar) response = http.send_put().response return response