Skip to content

Commit

Permalink
Merge pull request #47 from Adnuntius/post-json
Browse files Browse the repository at this point in the history
Add 'json' parameter to post() method in ApiClient
  • Loading branch information
richard-adnuntius authored Aug 22, 2022
2 parents 03d26fe + 7cb9aae commit 607fed9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions adnuntius/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,31 +235,34 @@ def copy(self, object_id, data=None, args=None):
def defaults(self):
return self.query(sub_resource='defaults')

def post(self, object_id=None, data=None, args=None, sub_resource=None):
def post(self, object_id=None, data=None, json=None, args=None, sub_resource=None):
"""
Perform a POST request for the supplied object id.
:param object_id: object id used to construct the url
:param data: optional dictionary of form parameters
:param json: optional JSON object to POST
:param args optional dictionary of query parameters
:param sub_resource: optional sub resource
:return: dictionary of the JSON object returned
"""
if data is None:
if data is None and json is None:
data = {}
if args is None:
args = {}
headers = self.auth()
headers['Accept-Encoding'] = 'gzip'
headers['Accept'] = self.accept
headers.update(self.api.headers)
if json is not None:
headers['Content-Type'] = 'application/json'

url = self.baseUrl + self.version + "/" + self.resourceName
if object_id:
url += "/" + object_id
if sub_resource:
url += "/" + sub_resource

r = self.handle_err(self.session.post(url, headers=headers, data=data,
r = self.handle_err(self.session.post(url, headers=headers, data=data, json=json,
params=dict(list(self.api.defaultArgs.items()) + list(args.items()))))
if r.text == '':
return None
Expand Down

0 comments on commit 607fed9

Please sign in to comment.