Skip to content

Commit 45e945f

Browse files
committed
Starts adding better docstrings and type hinting; Improve library structure
1 parent b17f09a commit 45e945f

File tree

12 files changed

+690
-578
lines changed

12 files changed

+690
-578
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ Microsoft graph API wrapper for Microsoft Graph written in Python.
66
pip install microsoftgraph-python
77
```
88

9-
## Usage
10-
If you need an office 365 token, send office365 attribute in True like this:
11-
```
12-
from microsoftgraph.client import Client
13-
client = Client('CLIENT_ID', 'CLIENT_SECRET', account_type='common', office365=True) # by default common, thus account_type is optional parameter
14-
```
9+
## Before start
10+
To use Microsoft Graph to read and write resources on behalf of a user, your app must get an access token from
11+
the Microsoft identity platform and attach the token to requests that it sends to Microsoft Graph. The exact
12+
authentication flow that you will use to get access tokens will depend on the kind of app you are developing and
13+
whether you want to use OpenID Connect to sign the user in to your app. One common flow used by native and mobile
14+
apps and also by some Web apps is the OAuth 2.0 authorization code grant flow.
15+
16+
See https://docs.microsoft.com/en-us/graph/auth-v2-user
1517

16-
If you don't, just instance the library like this:
18+
## Usage
1719
```
1820
from microsoftgraph.client import Client
1921
client = Client('CLIENT_ID', 'CLIENT_SECRET', account_type='common') # by default common, thus account_type is optional parameter

microsoftgraph/calendar.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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

Comments
 (0)