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

Commit 52e4425

Browse files
author
Doug Mahugh
committed
add delete(), patch()
1 parent 88f7cde commit 52e4425

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

graphrest.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,31 @@ def api_endpoint(self, url):
9999
f"{self.config['resource']}{self.config['api_version']}/",
100100
url.lstrip('/'))
101101

102-
def get(self, endpoint, headers=None, stream=False):
102+
def delete(self, endpoint, *, headers=None, data=None, verify=False, params=None):
103+
"""Wrapper for authenticated HTTP DELETE to API endpoint.
104+
105+
endpoint = URL (can be partial; for example, 'me/contacts')
106+
headers = HTTP header dictionary; will be merged with graphrest's
107+
standard headers, which include access token
108+
data = HTTP request body
109+
verify = the Requests option for verifying SSL certificate; defaults
110+
to False for demo purposes. For more information see:
111+
http://docs.python-requests.org/en/master/user/advanced/#ssl-csert-verification
112+
params = query string parameters
113+
114+
Returns Requests response object.
115+
"""
116+
self.token_validation()
117+
return requests.delete(self.api_endpoint(endpoint),
118+
headers=self.headers(headers),
119+
data=data, verify=verify, params=params)
120+
121+
def get(self, endpoint='me', *, headers=None, stream=False):
103122
"""GET from API (authenticated with access token).
123+
endpoint = URL (can be partial; for example, 'me/contacts')
124+
headers = HTTP header dictionary; will be merged with graphrest's
125+
standard headers, which include access token
126+
stream = Requests streaming option; set to True for image data, etc.
104127
Returns JSON payload and HTTP status code.
105128
"""
106129

@@ -170,6 +193,25 @@ def logout(self, redirect_to=None):
170193
if redirect_to:
171194
bottle.redirect(redirect_to)
172195

196+
def patch(self, endpoint, *, headers=None, data=None, verify=False, params=None):
197+
"""Wrapper for authenticated HTTP PATCH to API endpoint.
198+
199+
endpoint = URL (can be partial; for example, 'me/contacts')
200+
headers = HTTP header dictionary; will be merged with graphrest's
201+
standard headers, which include access token
202+
data = HTTP request body
203+
verify = the Requests option for verifying SSL certificate; defaults
204+
to False for demo purposes. For more information see:
205+
http://docs.python-requests.org/en/master/user/advanced/#ssl-csert-verification
206+
params = query string parameters
207+
208+
Returns Requests response object.
209+
"""
210+
self.token_validation()
211+
return requests.patch(self.api_endpoint(endpoint),
212+
headers=self.http_request_headers(headers),
213+
data=data, verify=verify, params=params)
214+
173215
def post(self, endpoint, headers=None, data=None, verify=False, params=None):
174216
"""POST to API (authenticated with access token).
175217

0 commit comments

Comments
 (0)