Add post_json as some DCC objects are created with post requests.
authorDiane Trout <diane@ghic.org>
Tue, 10 Jun 2014 20:13:46 +0000 (13:13 -0700)
committerDiane Trout <diane@ghic.org>
Tue, 10 Jun 2014 23:40:38 +0000 (16:40 -0700)
considering the code is duplicated, there's probably a way to abstract
those functions.

htsworkflow/submission/encoded.py

index aa21aa42fc6bfa958aba36ae36066314afa99d3b..f056f8e198e989c230989031650562e4246c03c5 100644 (file)
@@ -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