Skip to content

Include update_event and delete_event into calendar.py. #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
matthewmgraf opened this issue Sep 30, 2022 · 1 comment
Closed

Include update_event and delete_event into calendar.py. #41

matthewmgraf opened this issue Sep 30, 2022 · 1 comment

Comments

@matthewmgraf
Copy link

matthewmgraf commented Sep 30, 2022

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)
@ingmferrer
Copy link
Contributor

Hello, I see you have a working snippet.

Any PR is welcome.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants