summaryrefslogtreecommitdiff
path: root/obsapi/httpapi.py
diff options
context:
space:
mode:
Diffstat (limited to 'obsapi/httpapi.py')
-rw-r--r--obsapi/httpapi.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/obsapi/httpapi.py b/obsapi/httpapi.py
index 81a8fd0..8334224 100644
--- a/obsapi/httpapi.py
+++ b/obsapi/httpapi.py
@@ -2,6 +2,7 @@
#
import requests
from requests.auth import HTTPBasicAuth
+from null import Null
try:
import osc.conf as osc_conf
@@ -20,7 +21,7 @@ class ObsHttpApi(object):
def __init__(self, apiurl=None):
self.apiurl = apiurl or DEFAULTAPIURL
self.__get_auth()
- self._response = None
+ self._response = Null()
self.retries = 3
self.verify_ssl = True
@@ -41,8 +42,9 @@ class ObsHttpApi(object):
def __api_get(self, api, params=None):
+ url = '{0}{1}{2}'.format(self.apiurl, self.rootapi, api)
+
def try_get():
- url = '{0}{1}{2}'.format(self.apiurl, self.rootapi, api)
r = requests.get(url,
auth=self.auth,
params=params,
@@ -62,17 +64,30 @@ class ObsHttpApi(object):
return r
- def __api_put(self, api, data):
+ def __api_put(self, api, data, params=None):
url = '{0}{1}{2}'.format(self.apiurl, self.rootapi, api)
r = requests.put(url,
auth=self.auth,
data=data,
+ params=params,
verify=self.verify_ssl)
self._response = r
return r
+ def __api_post(self, api, data, params=None):
+
+ url = '{0}{1}{2}'.format(self.apiurl, self.rootapi, api)
+ r = requests.post(url,
+ auth=self.auth,
+ data=data,
+ params=params,
+ verify=self.verify_ssl)
+ self._response = r
+
+ return r
+
@property
def response(self):
'''Return requests response from last api query'''
@@ -92,12 +107,18 @@ class ObsHttpApi(object):
api = self.__api(*args)
r = self.__api_get(api, params=params)
if not self.success:
- print self.response
return self.default_xml
return r.text
- def put(self, args, data):
+ def put(self, *args, **kwargs):
+ data = kwargs.pop('data', None)
+ api = self.__api(*args)
+ r = self.__api_put(api, data=data, params=kwargs)
+ return r
+
+ def post(self, *args, **kwargs):
+ data = kwargs.pop('data', None)
api = self.__api(*args)
- r = self.__api_put(api, data)
+ r = self.__api_post(api, data=data, params=kwargs)
return r