Skip to content

Commit

Permalink
Expose data and params kwargs for request helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Chan authored and henrylamchan committed Mar 18, 2020
1 parent def7f11 commit 62cb40e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Byte-compiled / optimized / DLL files
__pycache__/
**/*.pyc
*.py[cod]
*$py.class

Expand Down
2 changes: 1 addition & 1 deletion workos/audit_trail.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def create_event(self, event, idempotency_key=None):
return self.request_helper.request(
EVENTS_PATH,
method=REQUEST_METHOD_POST,
params=event,
data=event,
headers=headers,
token=workos.api_key,
)
16 changes: 10 additions & 6 deletions workos/utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ def generate_api_url(self, path):
return self.base_api_url.format(path)

def request(
self, path, method=REQUEST_METHOD_GET, params=None, headers=None, token=None
self,
path,
method=REQUEST_METHOD_GET,
data=None,
params=None,
headers=None,
token=None,
):
"""Executes a request against the WorkOS API.
Expand All @@ -58,11 +64,9 @@ def request(
headers.update(BASE_HEADERS)
url = self.generate_api_url(path)

request_fn = getattr(requests, method)
if method == REQUEST_METHOD_GET:
response = request_fn(url, headers=headers, params=params)
else:
response = request_fn(url, headers=headers, data=params)
response = getattr(requests, method)(
url, headers=headers, data=data, params=params
)

status_code = response.status_code
if status_code >= 400 and status_code < 500:
Expand Down

0 comments on commit 62cb40e

Please sign in to comment.