Skip to content
This repository was archived by the owner on Mar 7, 2020. It is now read-only.

Commit d8e4fa7

Browse files
author
Doug Mahugh
committed
add other HTTP verb methods
1 parent 52e4425 commit d8e4fa7

1 file changed

Lines changed: 31 additions & 7 deletions

File tree

graphrest.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,19 @@ def delete(self, endpoint, *, headers=None, data=None, verify=False, params=None
118118
headers=self.headers(headers),
119119
data=data, verify=verify, params=params)
120120

121-
def get(self, endpoint='me', *, headers=None, stream=False):
122-
"""GET from API (authenticated with access token).
121+
def get(self, endpoint='me', *, headers=None, stream=False, verify=False, params=None):
122+
"""Wrapper for authenticated HTTP GET to API endpoint.
123+
123124
endpoint = URL (can be partial; for example, 'me/contacts')
124125
headers = HTTP header dictionary; will be merged with graphrest's
125126
standard headers, which include access token
126127
stream = Requests streaming option; set to True for image data, etc.
127-
Returns JSON payload and HTTP status code.
128+
verify = the Requests option for verifying SSL certificate; defaults
129+
to False for demo purposes. For more information see:
130+
http://docs.python-requests.org/en/master/user/advanced/#ssl-csert-verification
131+
params = query string parameters
132+
133+
Returns Requests response object.
128134
"""
129135

130136
self.token_validation()
@@ -134,10 +140,9 @@ def get(self, endpoint='me', *, headers=None, stream=False):
134140
if headers:
135141
merged_headers.update(headers)
136142

137-
response = requests.get(self.api_endpoint(endpoint),
138-
headers=merged_headers,
139-
stream=stream)
140-
return response.json(), response.status_code
143+
return requests.get(self.api_endpoint(endpoint),
144+
headers=merged_headers,
145+
stream=stream, verify=verify, params=params)
141146

142147
def headers(self, headers=None):
143148
"""Returns dictionary of default HTTP headers for calls to Microsoft Graph API,
@@ -232,6 +237,25 @@ def post(self, endpoint, headers=None, data=None, verify=False, params=None):
232237
headers=merged_headers, data=data,
233238
verify=verify, params=params)
234239

240+
def put(self, endpoint, *, headers=None, data=None, verify=False, params=None):
241+
"""Wrapper for authenticated HTTP PUT to API endpoint.
242+
243+
endpoint = URL (can be partial; for example, 'me/contacts')
244+
headers = HTTP header dictionary; will be merged with graphrest's
245+
standard headers, which include access token
246+
data = HTTP request body
247+
verify = the Requests option for verifying SSL certificate; defaults
248+
to False for demo purposes. For more information see:
249+
http://docs.python-requests.org/en/master/user/advanced/#ssl-csert-verification
250+
params = query string parameters
251+
252+
Returns Requests response object.
253+
"""
254+
self.token_validation()
255+
return requests.put(self.api_endpoint(endpoint),
256+
headers=self.headers(headers),
257+
data=data, verify=verify, params=params)
258+
235259
def redirect_uri_handler(self):
236260
"""Redirect URL handler for AuthCode workflow. Uses the authorization
237261
code received from auth endpoint to call the token endpoint and obtain

0 commit comments

Comments
 (0)