Add support for HEAD and PATCH

Change-Id: Ic874c49b791e9d2cb3d44b15511cbb467a551589
This commit is contained in:
Dolph Mathews
2012-09-11 11:06:54 -05:00
parent 4e0af25f22
commit b91cdf492a
2 changed files with 13 additions and 2 deletions

View File

@@ -78,6 +78,10 @@ class Manager(object):
resp, body = self.api.get(url)
return self.resource_class(self, body[response_key], loaded=True)
def _head(self, url):
resp, body = self.api.head(url)
return resp.status == 204
def _create(self, url, body, response_key, return_raw=False):
resp, body = self.api.post(url, body=body)
if return_raw:
@@ -87,9 +91,10 @@ class Manager(object):
def _delete(self, url):
resp, body = self.api.delete(url)
def _update(self, url, body, response_key=None, method="PUT"):
def _update(self, url, body=None, response_key=None, method="PUT"):
methods = {"PUT": self.api.put,
"POST": self.api.post}
"POST": self.api.post,
"PATCH": self.api.patch}
try:
resp, body = methods[method](url, body=body)
except KeyError:

View File

@@ -176,11 +176,17 @@ class HTTPClient(httplib2.Http):
def get(self, url, **kwargs):
return self._cs_request(url, 'GET', **kwargs)
def head(self, url, **kwargs):
return self._cs_request(url, 'HEAD', **kwargs)
def post(self, url, **kwargs):
return self._cs_request(url, 'POST', **kwargs)
def put(self, url, **kwargs):
return self._cs_request(url, 'PUT', **kwargs)
def patch(self, url, **kwargs):
return self._cs_request(url, 'PATCH', **kwargs)
def delete(self, url, **kwargs):
return self._cs_request(url, 'DELETE', **kwargs)