|
1 | 1 | from microsoftgraph.decorators import token_required |
2 | 2 | from microsoftgraph.response import Response |
| 3 | +from datetime import datetime |
3 | 4 |
|
4 | 5 |
|
5 | 6 | class Calendar(object): |
6 | | - def __init__(self, client): |
| 7 | + def __init__(self, client) -> None: |
| 8 | + """Working with Outlook Calendar. |
| 9 | +
|
| 10 | + https://docs.microsoft.com/en-us/graph/api/resources/calendar?view=graph-rest-1.0 |
| 11 | +
|
| 12 | + Args: |
| 13 | + client (Client): Library Client. |
| 14 | + """ |
7 | 15 | self._client = client |
8 | 16 |
|
9 | 17 | @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. |
| 18 | + def list_events(self) -> Response: |
| 19 | + """Get a list of event objects in the user's mailbox. The list contains single instance meetings and series |
| 20 | + masters. |
13 | 21 |
|
14 | | - Currently, this operation returns event bodies in only HTML format. |
| 22 | + https://docs.microsoft.com/en-us/graph/api/user-list-events?view=graph-rest-1.0&tabs=http |
15 | 23 |
|
16 | 24 | Returns: |
17 | | - A dict. |
18 | | -
|
| 25 | + Response: Microsoft Graph Response. |
19 | 26 | """ |
20 | 27 | return self._client._get(self._client.base_url + "me/events") |
21 | 28 |
|
22 | 29 | @token_required |
23 | | - def create_calendar_event( |
| 30 | + def create_event( |
24 | 31 | self, |
25 | 32 | subject: str, |
26 | 33 | content: str, |
27 | | - start_datetime: str, |
| 34 | + start_datetime: datetime, |
28 | 35 | start_timezone: str, |
29 | | - end_datetime: str, |
| 36 | + end_datetime: datetime, |
30 | 37 | end_timezone: str, |
31 | 38 | location: str, |
32 | 39 | calendar: str = None, |
| 40 | + content_type: str = "HTML", |
33 | 41 | **kwargs, |
34 | 42 | ) -> Response: |
35 | | - """ |
36 | | - Create a new calendar event. |
| 43 | + """Create an event in the user's default calendar or specified calendar. |
| 44 | +
|
| 45 | + https://docs.microsoft.com/en-us/graph/api/user-post-events?view=graph-rest-1.0&tabs=http |
| 46 | +
|
| 47 | + Additional time zones: https://docs.microsoft.com/en-us/graph/api/resources/datetimetimezone?view=graph-rest-1.0 |
37 | 48 |
|
38 | 49 | 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: |
| 50 | + subject (str): The text of the event's subject line. |
| 51 | + content (str): The body of the message associated with the event. |
| 52 | + start_datetime (datetime): A single point of time in a combined date and time representation ({date}T{time}; |
| 53 | + start_timezone (datetime): Represents a time zone, for example, "Pacific Standard Time". |
| 54 | + end_datetime (str): A single point of time in a combined date and time representation ({date}T{time}; for |
| 55 | + end_timezone (str): Represents a time zone, for example, "Pacific Standard Time". |
| 56 | + location (str): The location of the event. |
| 57 | + calendar (str, optional): Calendar ID. Defaults to None. |
| 58 | + content_type (str, optional): It can be in HTML or text format. Defaults to HTML. |
49 | 59 |
|
50 | 60 | Returns: |
51 | | - A dict. |
52 | | -
|
| 61 | + Response: Microsoft Graph Response. |
53 | 62 | """ |
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']] |
| 63 | + if isinstance(start_datetime, datetime): |
| 64 | + start_datetime = start_datetime.strftime("%Y-%m-%dT%H:%M:%S.%f") |
| 65 | + if isinstance(end_datetime, datetime): |
| 66 | + start_datetime = start_datetime.strftime("%Y-%m-%dT%H:%M:%S.%f") |
| 67 | + |
62 | 68 | body = { |
63 | 69 | "subject": subject, |
64 | | - "body": {"contentType": "HTML", "content": content}, |
65 | | - "start": {"dateTime": start_datetime, "timeZone": start_timezone}, |
66 | | - "end": {"dateTime": end_datetime, "timeZone": end_timezone}, |
| 70 | + "body": { |
| 71 | + "contentType": content_type, |
| 72 | + "content": content, |
| 73 | + }, |
| 74 | + "start": { |
| 75 | + "dateTime": start_datetime, |
| 76 | + "timeZone": start_timezone, |
| 77 | + }, |
| 78 | + "end": { |
| 79 | + "dateTime": end_datetime, |
| 80 | + "timeZone": end_timezone, |
| 81 | + }, |
67 | 82 | "location": {"displayName": location}, |
68 | | - # "attendees": attendees_list |
69 | 83 | } |
70 | 84 | url = "me/calendars/{}/events".format(calendar) if calendar is not None else "me/events" |
71 | 85 | return self._client._post(self._client.base_url + url, json=body) |
72 | 86 |
|
73 | 87 | @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. |
| 88 | + def list_calendars(self) -> Response: |
| 89 | + """Get all the user's calendars (/calendars navigation property), get the calendars from the default calendar |
| 90 | + group or from a specific calendar group. |
79 | 91 |
|
80 | | - When an event is sent, the server sends invitations to all the attendees. |
81 | | -
|
82 | | - Args: |
83 | | - name: |
| 92 | + https://docs.microsoft.com/en-us/graph/api/user-list-calendars?view=graph-rest-1.0&tabs=http |
84 | 93 |
|
85 | 94 | Returns: |
86 | | - A dict. |
87 | | -
|
| 95 | + Response: Microsoft Graph Response. |
88 | 96 | """ |
89 | | - body = {"name": "{}".format(name)} |
90 | | - return self._client._post(self._client.base_url + "me/calendars", json=body) |
| 97 | + return self._client._get(self._client.base_url + "me/calendars") |
91 | 98 |
|
92 | 99 | @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. |
| 100 | + def create_calendar(self, name: str) -> Response: |
| 101 | + """Create a new calendar for a user. |
96 | 102 |
|
97 | | - Returns: |
98 | | - A dict. |
| 103 | + https://docs.microsoft.com/en-us/graph/api/user-post-calendars?view=graph-rest-1.0&tabs=http |
| 104 | +
|
| 105 | + Args: |
| 106 | + name (str): The calendar name. |
99 | 107 |
|
| 108 | + Returns: |
| 109 | + Response: Microsoft Graph Response. |
100 | 110 | """ |
101 | | - return self._client._get(self._client.base_url + "me/calendars") |
| 111 | + body = {"name": "{}".format(name)} |
| 112 | + return self._client._post(self._client.base_url + "me/calendars", json=body) |
0 commit comments