Skip to content

Commit cedaea4

Browse files
committed
Document graph_session.py and constants.py
1 parent 70a8191 commit cedaea4

File tree

2 files changed

+58
-9
lines changed

2 files changed

+58
-9
lines changed

msgraphcore/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
BASE_URL = 'https://graph.microsoft.com/v1.0'
77
SDK_VERSION = '0.0.1-0'
88

9-
# MiddlewareOptions
9+
# Used as the key for AuthMiddlewareOption in MiddlewareControl
1010
AUTH_MIDDLEWARE_OPTIONS = 'AUTH_MIDDLEWARE_OPTIONS'

msgraphcore/graph_session.py

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Graph Session
33
"""
44

5-
from requests import Session, Response
5+
from requests import Session
66

77
from msgraphcore.constants import BASE_URL, SDK_VERSION
88
from msgraphcore.middleware._middleware import MiddlewarePipeline, BaseMiddleware
@@ -12,8 +12,11 @@
1212

1313

1414
class GraphSession(Session):
15-
"""
16-
Extends session object with graph functionality
15+
"""Extends Session with Graph functionality
16+
17+
Extends Session by adding support for middleware options and middleware pipeline
18+
19+
1720
"""
1821
def __init__(self, auth_provider: AuthProviderBase, middleware: list = []):
1922
super().__init__()
@@ -26,33 +29,79 @@ def __init__(self, auth_provider: AuthProviderBase, middleware: list = []):
2629
self._register(middleware)
2730

2831
@middleware_control.get_middleware_options
29-
def get(self, url, **kwargs):
32+
def get(self, url: str, **kwargs):
33+
r"""Sends a GET request. Returns :class:`Response` object.
34+
35+
:param url: URL for the new :class:`Request` object.
36+
:param \*\*kwargs: Optional arguments that ``request`` takes.
37+
:rtype: requests.Response
38+
"""
3039
return super().get(self._graph_url(url))
3140

3241
@middleware_control.get_middleware_options
3342
def post(self, url, data=None, json=None, **kwargs):
43+
r"""Sends a POST request. Returns :class:`Response` object.
44+
45+
:param url: URL for the new :class:`Request` object.
46+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
47+
object to send in the body of the :class:`Request`.
48+
:param json: (optional) json to send in the body of the :class:`Request`.
49+
:param \*\*kwargs: Optional arguments that ``request`` takes.
50+
:rtype: requests.Response
51+
"""
3452
return super().post(self._graph_url(url), data, json, **kwargs)
3553

3654
@middleware_control.get_middleware_options
3755
def put(self, url, data=None, **kwargs):
56+
r"""Sends a PUT request. Returns :class:`Response` object.
57+
58+
:param url: URL for the new :class:`Request` object.
59+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
60+
object to send in the body of the :class:`Request`.
61+
:param \*\*kwargs: Optional arguments that ``request`` takes.
62+
:rtype: requests.Response
63+
"""
3864
return super().put(self._graph_url(url), data, **kwargs)
3965

4066
@middleware_control.get_middleware_options
4167
def patch(self, url, data=None, **kwargs):
68+
r"""Sends a PATCH request. Returns :class:`Response` object.
69+
70+
:param url: URL for the new :class:`Request` object.
71+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
72+
object to send in the body of the :class:`Request`.
73+
:param \*\*kwargs: Optional arguments that ``request`` takes.
74+
:rtype: requests.Response
75+
"""
4276
return super().patch(self._graph_url(url), data, **kwargs)
4377

4478
@middleware_control.get_middleware_options
4579
def delete(self, url, **kwargs):
80+
r"""Sends a DELETE request. Returns :class:`Response` object.
81+
82+
:param url: URL for the new :class:`Request` object.
83+
:param \*\*kwargs: Optional arguments that ``request`` takes.
84+
:rtype: requests.Response
85+
"""
4686
return super().delete(url, **kwargs)
4787

48-
def _graph_url(self, url: str) -> Response:
88+
def _graph_url(self, url: str) -> str:
89+
"""Appends BASE_URL to user provided path
90+
91+
:param url: user provided path
92+
:return: graph_url
93+
"""
4994
return self._base_url+url if (url[0] == '/') else url
5095

5196
def _register(self, middleware: [BaseMiddleware]) -> None:
97+
"""Adds middleware to middleware_pipeline
98+
99+
:param middleware: list of middleware
100+
"""
52101
if middleware:
53-
middleware_adapter = MiddlewarePipeline()
102+
middleware_pipeline = MiddlewarePipeline()
54103

55104
for ware in middleware:
56-
middleware_adapter.add_middleware(ware)
105+
middleware_pipeline.add_middleware(ware)
57106

58-
self.mount('https://', middleware_adapter)
107+
self.mount('https://', middleware_pipeline)

0 commit comments

Comments
 (0)