Skip to content

Commit 87edd11

Browse files
committed
add drive items
1 parent ff90ffe commit 87edd11

File tree

5 files changed

+453
-12
lines changed

5 files changed

+453
-12
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"python.linting.enabled": true,
3-
"python.linting.pylintEnabled": true
3+
// "python.linting.pylintEnabled": true
44
}

ms_graph/client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ms_graph.groups import Groups
1818
from ms_graph.notes import Notes
1919
from ms_graph.session import GraphSession
20+
from ms_graph.drive_items import DriveItems
2021

2122
from urllib.parse import urlencode, urlparse, quote_plus
2223

@@ -355,6 +356,20 @@ def drives(self) -> Drives:
355356

356357
return drives_object
357358

359+
def drive_item(self) -> DriveItems:
360+
"""Used to access the Drive Items Services and metadata.
361+
362+
### Returns
363+
---
364+
DriveItems:
365+
The `DriveItems` services Object.
366+
"""
367+
368+
# Grab the Drive Items Object for the session.
369+
drive_items_object: Drives = DriveItems(session=self.graph_session)
370+
371+
return drive_items_object
372+
358373
def groups(self) -> Groups:
359374
"""Used to access the Groups Services and metadata.
360375

ms_graph/drive_items.py

Lines changed: 316 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,319 @@ def __init__(self, session: object) -> None:
3030

3131
# Set the endpoint.
3232
self.endpoint = 'drive'
33-
self.collections_endpoint = 'drives'
33+
self.collections_endpoint = 'drives/'
34+
35+
36+
def get_drive_item(self, drive_id: str, item_id: str) -> Dict:
37+
"""Grab's a DriveItem Resource using the Item ID and Drive ID.
38+
39+
### Parameters
40+
----
41+
drive_id : str
42+
The Drive ID in which the resource exist.
43+
44+
item_id : str
45+
The item ID of the object you want to
46+
return.
47+
48+
### Returns
49+
----
50+
Dict:
51+
A DriveItem resource object.
52+
"""
53+
54+
content = self.graph_session.make_request(
55+
method='get',
56+
endpoint= self.collections_endpoint + "/{drive_id}/items/{item_id}".format(
57+
drive_id=drive_id,
58+
item_id=item_id
59+
)
60+
)
61+
62+
return content
63+
64+
def get_drive_item_by_path(self, drive_id: str, item_path: str) -> Dict:
65+
"""Grab's a DriveItem Resource using the Item ID and Drive ID.
66+
67+
### Parameters
68+
----
69+
drive_id : str
70+
The Drive ID in which the resource exist.
71+
72+
item_path : str
73+
The path to the Item.
74+
75+
### Returns
76+
----
77+
Dict:
78+
A DriveItem resource object.
79+
"""
80+
81+
content = self.graph_session.make_request(
82+
method='get',
83+
endpoint= self.collections_endpoint + "/{drive_id}/root:/{path}".format(
84+
drive_id=drive_id,
85+
path=item_path
86+
)
87+
)
88+
89+
return content
90+
91+
def get_group_drive_item(self, group_id: str, item_id: str) -> Dict:
92+
"""Grab's a DriveItem Resource using the Item ID and Drive ID.
93+
94+
### Parameters
95+
----
96+
group_id : str
97+
The Group ID in which the resource exist.
98+
99+
item_id : str
100+
The item ID of the object you want to
101+
return.
102+
103+
### Returns
104+
----
105+
Dict:
106+
A DriveItem resource object.
107+
"""
108+
109+
content = self.graph_session.make_request(
110+
method='get',
111+
endpoint= "/groups/{group_id}/drive/items/{item_id}".format(
112+
group_id=group_id,
113+
item_id=item_id
114+
)
115+
)
116+
117+
return content
118+
119+
def get_group_drive_item_by_path(self, group_id: str, item_path: str) -> Dict:
120+
"""Grab's a DriveItem Resource using the Item ID and Drive ID.
121+
122+
### Parameters
123+
----
124+
drive_id : str
125+
The Drive ID in which the resource exist.
126+
127+
item_path : str
128+
The path to the Item.
129+
130+
### Returns
131+
----
132+
Dict:
133+
A DriveItem resource object.
134+
"""
135+
136+
content = self.graph_session.make_request(
137+
method='get',
138+
endpoint= "/groups/{group_id}/drive/root:/{item_path}".format(
139+
group_id=group_id,
140+
item_path=item_path
141+
)
142+
)
143+
144+
return content
145+
146+
def get_my_drive_item(self, item_id: str) -> Dict:
147+
"""Grab's a DriveItem Resource using the Item ID and Drive ID.
148+
149+
### Parameters
150+
----
151+
item_id : str
152+
The item ID of the object you want to
153+
return.
154+
155+
### Returns
156+
----
157+
Dict:
158+
A DriveItem resource object.
159+
"""
160+
161+
content = self.graph_session.make_request(
162+
method='get',
163+
endpoint= "/me/drive/items/{item_id}".format(
164+
item_id=item_id
165+
)
166+
)
167+
168+
return content
169+
170+
def get_my_drive_item_by_path(self, item_path: str) -> Dict:
171+
"""Grab's a DriveItem Resource using the Item ID and Drive ID.
172+
173+
### Parameters
174+
----
175+
item_path : str
176+
The path to the Item.
177+
178+
### Returns
179+
----
180+
Dict:
181+
A DriveItem resource object.
182+
"""
183+
184+
content = self.graph_session.make_request(
185+
method='get',
186+
endpoint= "/me/drive/root:/{item_path}".format(
187+
item_path=item_path
188+
)
189+
)
190+
191+
return content
192+
193+
def get_site_drive_item(self, site_id: str, item_id: str) -> Dict:
194+
"""Grab's a DriveItem Resource using the Item ID and Drive ID.
195+
196+
### Parameters
197+
----
198+
site_id : str
199+
The site ID which to query the item from.
200+
201+
item_id : str
202+
The item ID of the object you want to
203+
return.
204+
205+
### Returns
206+
----
207+
Dict:
208+
A DriveItem resource object.
209+
"""
210+
211+
content = self.graph_session.make_request(
212+
method='get',
213+
endpoint= "/sites/{site_id}/drive/items/{item_id}".format(
214+
site_id=site_id,
215+
item_id=item_id
216+
)
217+
)
218+
219+
return content
220+
221+
def get_site_drive_item_by_path(self, site_id: str, item_path: str) -> Dict:
222+
"""Grab's a DriveItem Resource using the Item ID and Drive ID.
223+
224+
### Parameters
225+
----
226+
site_id : str
227+
The site ID which to query the item from.
228+
229+
item_path : str
230+
The path to the Item.
231+
232+
### Returns
233+
----
234+
Dict:
235+
A DriveItem resource object.
236+
"""
237+
238+
content = self.graph_session.make_request(
239+
method='get',
240+
endpoint= "/sites/{site_id}/drive/root:/{item_path}".format(
241+
site_id=site_id,
242+
item_path=item_path
243+
)
244+
)
245+
246+
return content
247+
248+
def get_site_drive_item_from_list(self, site_id: str, list_id: str, item_id: str) -> Dict:
249+
"""Grab's a DriveItem Resource using the Item ID and Drive ID.
250+
251+
### Parameters
252+
----
253+
site_id : str
254+
The site ID which to query the item from.
255+
256+
list_id : str
257+
The list ID which to query the item from.
258+
259+
item_id : str
260+
The item ID of the object you want to
261+
return.
262+
263+
### Returns
264+
----
265+
Dict:
266+
A DriveItem resource object.
267+
"""
268+
269+
content = self.graph_session.make_request(
270+
method='get',
271+
endpoint= "/sites/{site_id}/lists/{list_id}/items/{item_id}/driveItem".format(
272+
site_id=site_id,
273+
list_id=list_id,
274+
item_id=item_id
275+
)
276+
)
277+
278+
return content
279+
280+
def get_user_drive_item(self, user_id: str, item_id: str) -> Dict:
281+
"""Grab's a DriveItem Resource using the Item ID and Drive ID.
282+
283+
### Parameters
284+
----
285+
user_id : str
286+
The User ID which to query the item from.
287+
288+
item_id : str
289+
The item ID of the object you want to
290+
return.
291+
292+
### Returns
293+
----
294+
Dict:
295+
A DriveItem resource object.
296+
"""
297+
298+
content = self.graph_session.make_request(
299+
method='get',
300+
endpoint= "/users/{user_id}/drive/items/{item_id}".format(
301+
user_id=user_id,
302+
item_id=item_id
303+
)
304+
)
305+
306+
return content
307+
308+
def get_user_drive_item_by_path(self, user_id: str, item_path: str) -> Dict:
309+
"""Grab's a DriveItem Resource using the Item ID and Drive ID.
310+
311+
### Parameters
312+
----
313+
site_id : str
314+
The User ID which to query the item from.
315+
316+
item_path : str
317+
The path to the Item.
318+
319+
### Returns
320+
----
321+
Dict:
322+
A DriveItem resource object.
323+
"""
324+
325+
content = self.graph_session.make_request(
326+
method='get',
327+
endpoint= "/users/{user_id}/drive/root:/{item_path}".format(
328+
user_id=user_id,
329+
item_path=item_path
330+
)
331+
)
332+
333+
return content
334+
335+
336+
# GET /drives/{drive-id}/items/{item-id}
337+
# GET /drives/{drive-id}/root:/{item-path}
338+
# GET /groups/{group-id}/drive/items/{item-id}
339+
# GET /groups/{group-id}/drive/root:/{item-path}
340+
# GET /me/drive/items/{item-id}
341+
# GET /me/drive/root:/{item-path}
342+
343+
# GET /sites/{site-id}/drive/items/{item-id}
344+
# GET /sites/{site-id}/drive/root:/{item-path}
345+
# GET /sites/{site-id}/lists/{list-id}/items/{item-id}/driveItem
346+
347+
# GET /users/{user-id}/drive/items/{item-id}
348+
# GET /users/{user-id}/drive/root:/{item-path}

samples/use_drive_services.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
'Directory.ReadWrite.All',
1111
'User.Read.All',
1212
'Directory.Read.All',
13-
'Directory.ReadWrite.All',
14-
# 'offline_access',
15-
# 'openid',
16-
# 'profile'
13+
'Directory.ReadWrite.All'
1714
]
1815

1916
# Initialize the Parser.
@@ -45,14 +42,14 @@
4542
# List the Root Drive.
4643
pprint(drive_services.get_root_drive())
4744

48-
# # List the Root Drive Deltas.
49-
# pprint(drive_services.get_root_drive_delta())
45+
# List the Root Drive Deltas.
46+
pprint(drive_services.get_root_drive_delta())
5047

51-
# # List the Root Drive Children.
52-
# pprint(drive_services.get_root_drive_children())
48+
# List the Root Drive Children.
49+
pprint(drive_services.get_root_drive_children())
5350

54-
# # List the Root Drive Followers
55-
# pprint(drive_services.get_root_drive_followed())
51+
# List the Root Drive Followers
52+
pprint(drive_services.get_root_drive_followed())
5653

5754
# Grab a Drive by id.
5855
pprint(drive_services.get_drive_by_id(drive_id='8bc640c57cda25b6'))

0 commit comments

Comments
 (0)