From e3d98b912474142affa7a76ca4c2d763f186b9ba Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Tue, 10 Jun 2014 13:13:46 -0700 Subject: [PATCH] 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. --- htsworkflow/submission/encoded.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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 -- 2.30.2