From: Diane Trout Date: Tue, 10 Jun 2014 20:13:46 +0000 (-0700) Subject: Add post_json as some DCC objects are created with post requests. X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=e3d98b912474142affa7a76ca4c2d763f186b9ba Add post_json as some DCC objects are created with post requests. considering the code is duplicated, there's probably a way to abstract those functions. --- diff --git a/htsworkflow/submission/encoded.py b/htsworkflow/submission/encoded.py index aa21aa4..f056f8e 100644 --- a/htsworkflow/submission/encoded.py +++ b/htsworkflow/submission/encoded.py @@ -254,6 +254,15 @@ class ENCODED: response.raise_for_status() return response.json() + def post_json(self, collection_id, new_object): + url = self.prepare_url(collection_id) + payload = json.dumps(new_object) + response = requests.post(url, auth=self.auth, headers=self.json_headers, data=payload) + if response.status_code != requests.codes.created: + LOGGER.error("Error http status: {}".format(response.status_code)) + response.raise_for_status() + return response.json() + def prepare_url(self, request_url): '''This attempts to provide some convienence for accessing a URL