1
+ from typing import List
2
+ from typing import Dict
3
+ from typing import Union
4
+
5
+ from ms_graph .session import GraphSession
6
+
7
+
8
+ class Notes ():
9
+
10
+ """
11
+ ## Overview:
12
+ ----
13
+ Microsoft Graph lets your app get authorized access to a user's
14
+ OneNote notebooks, sections, and pages in a personal or organization
15
+ account. With the appropriate delegated or application permissions,
16
+ your app can access the OneNote data of the signed-in user or any
17
+ user in a tenant.
18
+ """
19
+
20
+ def __init__ (self , session : object ) -> None :
21
+ """Initializes the `Notes` object.
22
+
23
+ ### Parameters
24
+ ----
25
+ session : object
26
+ An authenticated session for our Microsoft Graph Client.
27
+ """
28
+
29
+ # Set the session.
30
+ self .graph_session : GraphSession = session
31
+
32
+ # Set the endpoint.
33
+ self .endpoint = 'onenote'
34
+
35
+ def list_my_notebooks (self ) -> Dict :
36
+ """Retrieve a list of your notebook objects.
37
+
38
+ ### Returns
39
+ ----
40
+ Dict:
41
+ A List of `Notebook` Resource Object.
42
+ """
43
+
44
+ # define the endpoints.
45
+ endpoint = "me/" + self .endpoint + "/notebooks"
46
+
47
+ content = self .graph_session .make_request (
48
+ method = 'get' ,
49
+ endpoint = endpoint
50
+ )
51
+
52
+ return content
53
+
54
+ def list_user_notebooks (self , user_id : str ) -> Dict :
55
+ """Retrieve a list of notebook objects.
56
+
57
+ ### Parameters
58
+ ----
59
+ user_id (str): The User's ID that is assoicated with
60
+ their Graph account.
61
+
62
+ ### Returns
63
+ ----
64
+ Dict:
65
+ A List of `Notebook` Resource Object.
66
+ """
67
+
68
+ # Define the endpoint.
69
+ endpoint = "users/{user_id}" .format (user_id = user_id ) + \
70
+ self .endpoint + "/notebooks"
71
+
72
+ content = self .graph_session .make_request (
73
+ method = 'get' ,
74
+ endpoint = endpoint
75
+ )
76
+
77
+ return content
78
+
79
+ def list_group_notebooks (self , group_id : str ) -> Dict :
80
+ """Retrieve a list of notebook objects.
81
+
82
+ ### Parameters
83
+ ----
84
+ group_id (str): The Group ID that you want to pull
85
+ notebooks for.
86
+
87
+ ### Returns
88
+ ----
89
+ Dict:
90
+ A List of `Notebook` Resource Object.
91
+ """
92
+
93
+ # Define the endpoint.
94
+ endpoint = "groups/{group_id}" .format (
95
+ group_id = group_id ) + self .endpoint + "/notebooks"
96
+
97
+ content = self .graph_session .make_request (
98
+ method = 'get' ,
99
+ endpoint = endpoint
100
+ )
101
+
102
+ return content
103
+
104
+ def list_site_notebooks (self , site_id : str ) -> Dict :
105
+ """Retrieve a list of notebook objects.
106
+
107
+ ### Parameters
108
+ ----
109
+ site_id (str): The Site ID that you want to pull
110
+ notebooks for.
111
+
112
+ ### Returns
113
+ ----
114
+ Dict:
115
+ A List of `Notebook` Resource Object.
116
+ """
117
+
118
+ # Define the endpoint.
119
+ endpoint = "sites/{site_id}" .format (site_id = site_id ) + \
120
+ self .endpoint + "/notebooks"
121
+
122
+ content = self .graph_session .make_request (
123
+ method = 'get' ,
124
+ endpoint = endpoint
125
+ )
126
+
127
+ return content
128
+
129
+ def get_my_notebook (self , notebook_id : str ) -> Dict :
130
+ """Retrieve a list of notebook objects.
131
+
132
+ ### Parameters
133
+ ----
134
+ notebook_id (str): The User's Notebook ID that you
135
+ want to pull.
136
+
137
+ ### Returns
138
+ ----
139
+ Dict:
140
+ A List of `Notebook` Resource Object.
141
+ """
142
+
143
+ # define the endpoints.
144
+ endpoint = "me/" + self .endpoint + "/notebooks/{notebook_id}" .format (
145
+ notebook_id = notebook_id
146
+ )
147
+
148
+ content = self .graph_session .make_request (
149
+ method = 'get' ,
150
+ endpoint = endpoint
151
+ )
152
+
153
+ return content
154
+
155
+ def get_user_notebook (self , user_id : str , notebook_id : str ) -> Dict :
156
+ """Retrieve a notebook object from a user by it's ID.
157
+
158
+ ### Parameters
159
+ ----
160
+ user_id (str): The User's ID that is assoicated with
161
+ their Graph account.
162
+
163
+ notebook_id (str): The Notebook ID that you
164
+ want to pull.
165
+
166
+ ### Returns
167
+ ----
168
+ Dict:
169
+ A List of `Notebook` Resource Object.
170
+ """
171
+
172
+ # Define the endpoint.
173
+ endpoint = "users/{user_id}" .format (user_id = user_id ) + self .endpoint + "/notebooks/{notebook_id}" .format (
174
+ notebook_id = notebook_id
175
+ )
176
+
177
+ content = self .graph_session .make_request (
178
+ method = 'get' ,
179
+ endpoint = endpoint
180
+ )
181
+
182
+ return content
183
+
184
+ def get_group_notebook (self , group_id : str , notebook_id : str ) -> Dict :
185
+ """Retrieve a notebook object from a Group by it's ID.
186
+
187
+ ### Parameters
188
+ ----
189
+ group_id (str): The Group ID that you want to pull
190
+ notebooks for.
191
+
192
+ notebook_id (str): The Notebook ID that you
193
+ want to pull.
194
+
195
+ ### Returns
196
+ ----
197
+ Dict:
198
+ A List of `Notebook` Resource Object.
199
+ """
200
+
201
+ # Define the endpoint.
202
+ endpoint = "groups/{group_id}" .format (group_id = group_id ) + self .endpoint + "/notebooks/{notebook_id}" .format (
203
+ notebook_id = notebook_id
204
+ )
205
+
206
+ content = self .graph_session .make_request (
207
+ method = 'get' ,
208
+ endpoint = endpoint
209
+ )
210
+
211
+ return content
212
+
213
+ def get_site_notebook (self , site_id : str , notebook_id : str ) -> Dict :
214
+ """Retrieve a notebook object from a SharePoint Site by it's ID.
215
+
216
+ ### Parameters
217
+ ----
218
+ site_id (str): The Site ID that you want to pull
219
+ notebooks for.
220
+
221
+ notebook_id (str): The Notebook ID that you
222
+ want to pull.
223
+
224
+ ### Returns
225
+ ----
226
+ Dict:
227
+ A List of `Notebook` Resource Object.
228
+ """
229
+
230
+ # Define the endpoint.
231
+ endpoint = "sites/{site_id}" .format (site_id = site_id ) + self .endpoint + "/notebooks/{notebook_id}" .format (
232
+ notebook_id = notebook_id
233
+ )
234
+
235
+ content = self .graph_session .make_request (
236
+ method = 'get' ,
237
+ endpoint = endpoint
238
+ )
239
+
240
+ return content
241
+
242
+ def list_my_notebook_section (self , notebook_id : str ) -> Dict :
243
+ """Retrieve a list of onenoteSection objects from one of your notebooks.
244
+
245
+ ### Parameters
246
+ ----
247
+ notebook_id (str): The Notebook ID that you
248
+ want to pull.
249
+
250
+ ### Returns
251
+ ----
252
+ Dict:
253
+ A List of `Notebook` Resource Object.
254
+ """
255
+
256
+ # Define the endpoint.
257
+ endpoint = endpoint = "me/" + self .endpoint + "/notebooks/{notebook_id}" .format (
258
+ notebook_id = notebook_id
259
+ ) + "/sections"
260
+
261
+ content = self .graph_session .make_request (
262
+ method = 'get' ,
263
+ endpoint = endpoint
264
+ )
265
+
266
+ return content
0 commit comments