|
| 1 | +from microsoftgraph.decorators import token_required |
| 2 | +from microsoftgraph.response import Response |
| 3 | + |
| 4 | + |
| 5 | +class Calendar(object): |
| 6 | + def __init__(self, client): |
| 7 | + self._client = client |
| 8 | + |
| 9 | + @token_required |
| 10 | + def get_me_events(self) -> Response: |
| 11 | + """Get a list of event objects in the user's mailbox. The list contains single instance meetings and |
| 12 | + series masters. |
| 13 | +
|
| 14 | + Currently, this operation returns event bodies in only HTML format. |
| 15 | +
|
| 16 | + Returns: |
| 17 | + A dict. |
| 18 | +
|
| 19 | + """ |
| 20 | + return self._client._get(self._client.base_url + "me/events") |
| 21 | + |
| 22 | + @token_required |
| 23 | + def create_calendar_event( |
| 24 | + self, |
| 25 | + subject: str, |
| 26 | + content: str, |
| 27 | + start_datetime: str, |
| 28 | + start_timezone: str, |
| 29 | + end_datetime: str, |
| 30 | + end_timezone: str, |
| 31 | + location: str, |
| 32 | + calendar: str = None, |
| 33 | + **kwargs, |
| 34 | + ) -> Response: |
| 35 | + """ |
| 36 | + Create a new calendar event. |
| 37 | +
|
| 38 | + Args: |
| 39 | + subject: subject of event, string |
| 40 | + content: content of event, string |
| 41 | + start_datetime: in the format of 2017-09-04T11:00:00, dateTimeTimeZone string |
| 42 | + start_timezone: in the format of Pacific Standard Time, string |
| 43 | + end_datetime: in the format of 2017-09-04T11:00:00, dateTimeTimeZone string |
| 44 | + end_timezone: in the format of Pacific Standard Time, string |
| 45 | + location: string |
| 46 | + attendees: list of dicts of the form: |
| 47 | + {"emailAddress": {"address": a['attendees_email'],"name": a['attendees_name']} |
| 48 | + calendar: |
| 49 | +
|
| 50 | + Returns: |
| 51 | + A dict. |
| 52 | +
|
| 53 | + """ |
| 54 | + # TODO: attendees |
| 55 | + # attendees_list = [{ |
| 56 | + # "emailAddress": { |
| 57 | + # "address": a['attendees_email'], |
| 58 | + # "name": a['attendees_name'] |
| 59 | + # }, |
| 60 | + # "type": a['attendees_type'] |
| 61 | + # } for a in kwargs['attendees']] |
| 62 | + body = { |
| 63 | + "subject": subject, |
| 64 | + "body": {"contentType": "HTML", "content": content}, |
| 65 | + "start": {"dateTime": start_datetime, "timeZone": start_timezone}, |
| 66 | + "end": {"dateTime": end_datetime, "timeZone": end_timezone}, |
| 67 | + "location": {"displayName": location}, |
| 68 | + # "attendees": attendees_list |
| 69 | + } |
| 70 | + url = "me/calendars/{}/events".format(calendar) if calendar is not None else "me/events" |
| 71 | + return self._client._post(self._client.base_url + url, json=body) |
| 72 | + |
| 73 | + @token_required |
| 74 | + def create_calendar(self, name: str) -> Response: |
| 75 | + """Create an event in the user's default calendar or specified calendar. |
| 76 | +
|
| 77 | + You can specify the time zone for each of the start and end times of the event as part of these values, |
| 78 | + as the start and end properties are of dateTimeTimeZone type. |
| 79 | +
|
| 80 | + When an event is sent, the server sends invitations to all the attendees. |
| 81 | +
|
| 82 | + Args: |
| 83 | + name: |
| 84 | +
|
| 85 | + Returns: |
| 86 | + A dict. |
| 87 | +
|
| 88 | + """ |
| 89 | + body = {"name": "{}".format(name)} |
| 90 | + return self._client._post(self._client.base_url + "me/calendars", json=body) |
| 91 | + |
| 92 | + @token_required |
| 93 | + def get_me_calendars(self) -> Response: |
| 94 | + """Get all the user's calendars (/calendars navigation property), get the calendars from the default |
| 95 | + calendar group or from a specific calendar group. |
| 96 | +
|
| 97 | + Returns: |
| 98 | + A dict. |
| 99 | +
|
| 100 | + """ |
| 101 | + return self._client._get(self._client.base_url + "me/calendars") |
0 commit comments