Skip to content

Include update_event and delete_event into calendar.py. #41

Closed
@matthewmgraf

Description

@matthewmgraf

Here's the simplistic code for a head start that works for me. Of course you can edit parts to make it conventional, but adding this in is a huge value add and makes it easier for people to pick up the API.

@token_required
    def update_event(
        self,
        start_datetime: datetime,
        start_timezone: str,
        end_datetime: datetime,
        end_timezone: str,
        id: str,
        **kwargs,
    ) -> Response:
        """Update an event in the user's default calendar or specified calendar.

        https://docs.microsoft.com/en-us/graph/api/user-post-events?view=graph-rest-1.0&tabs=http

        Additional time zones: https://docs.microsoft.com/en-us/graph/api/resources/datetimetimezone?view=graph-rest-1.0

        Args:
            subject (str): The text of the event's subject line.
            content (str): The body of the message associated with the event.
            start_datetime (datetime): A single point of time in a combined date and time representation ({date}T{time};
            start_timezone (str): Represents a time zone, for example, "Pacific Standard Time".
            end_datetime (datetime): A single point of time in a combined date and time representation ({date}T{time}; for
            end_timezone (str): Represents a time zone, for example, "Pacific Standard Time".
            location (str): The location of the event.
            calendar_id (str, optional): Calendar ID. Defaults to None.
            content_type (str, optional): It can be in HTML or text format. Defaults to HTML.

        Returns:
            Response: Microsoft Graph Response.
        """
        if isinstance(start_datetime, datetime):
            start_datetime = format_time(start_datetime)
        if isinstance(end_datetime, datetime):
            end_datetime = format_time(end_datetime)

        body = {
            "start": {
                "dateTime": start_datetime,
                "timeZone": start_timezone,
            },
            "end": {
                "dateTime": end_datetime,
                "timeZone": end_timezone,
            },
        }
        body.update(kwargs)
        url = "me/events/{}".format(id)
        return self._client._patch(self._client.base_url + url, json=body)

    @token_required
    def delete_event(
        self,
        id: str
    ) -> Response:
        """Delete an event in the user's default calendar or specified calendar.

        https://docs.microsoft.com/en-us/graph/api/user-post-events?view=graph-rest-1.0&tabs=http

        Additional time zones: https://docs.microsoft.com/en-us/graph/api/resources/datetimetimezone?view=graph-rest-1.0

        Args:
            id (str): Event ID.

        Returns:
            Response: Microsoft Graph Response.
        """
        url = "me/events/{}".format(id)
        return self._client._delete(self._client.base_url + url)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions