Ejemplo n.º 1
0
 def patch(self, user_id, label_id, label_model):
     """
     Updates the specified label. This method supports patch semantics.
     :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]: Patch 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_patch()
     response_json = http.get_response_json(http.response)
     label_model = LabelModel().parse_response_to_model(response_json)
     log_info(
         '[Users.labels]: PATCH response: {status_code}, \n{model}'.format(
             status_code=http.get_response_status_code(http.response),
             model=label_model))
     return http.response, label_model
 def patch_send_as(self, user_id, send_as_email, json_body):
     """
     Modify 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, header=self.header)
     api.auth_to_google(client=client, scope=scope_gmail_settings)
     api.send_patch()
     return api.response
Ejemplo n.º 3
0
    def patch(self, json_data, rule_id):
        """
        Метод отпрвляет PATCH запрос для изменения правила применяемого к календарю

        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_patch()

        return http.response
Ejemplo n.º 4
0
    def patch_event(self, calendar_id, event_id, new_event):
        url = "{host}/{api}/calendars/{calendar_id}/events/{event_id}".\
            format(host=self.host, api=self.api, calendar_id=calendar_id, event_id=event_id)
        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))
        req.auth_to_google(client=client, scope=scope_calendar)
        req.send_patch()
        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
Ejemplo n.º 5
0
 def patch_calendar(self, calendar_model_output, calendar_model_initial):
     """
         Patch calendar.
     This operation patch calendar in the primary calendar of an account.
     :param  calendar_model_output
             calendar_model_initial
     :return:    response
     """
     log_info("Patch calendar...")
     json_patch = 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_patch)
     http.auth_to_google(client=client, scope=scope_calendar)
     response = http.send_patch().response
     return response
 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