def delete(self, resource_id, params={}): """ Delete resource record. Required Arguments: resource_id The resource id Optional Arguments: params Some resource might allow additional parameters. For example, the user resource has a 'rdikwid' (really delete I know what I'm doing) option which causes a user to *really* be deleted (normally deletion only sets the status to 'Deleted'). """ path = '/%s/%s' % (self.path, resource_id) try: response = self.api.make_request('DELETE', path, params) except exc.dRestRequestError as e: msg = "%s (resource: %s, id: %s)" % (e.msg, self.name, resource_id) raise exc.dRestRequestError(msg, e.response) return response
def get(self, resource_id=None, params={}): """ Get all records for a resource, or a single resource record. Optional Arguments: resource_id The resource id (may also be a label in some environments). params Additional request parameters to pass along. """ if resource_id: path = '/%s/%s' % (self.path, resource_id) else: path = '/%s' % self.path try: response = self.api.make_request('GET', path, params=self.filter(params)) except exc.dRestRequestError as e: msg = "%s (resource: %s, id: %s)" % (e.msg, self.name, resource_id) raise exc.dRestRequestError(msg, e.response) return response
def put(self, resource_id, params={}): """ Update an existing resource. Required Arguments: resource_id The id of the resource to update. params A dictionary of parameters (different for every resource). """ params = self.filter(params) path = '/%s/%s' % (self.path, resource_id) try: response = self.api.make_request('PUT', path, params) except exc.dRestRequestError as e: msg = "%s (resource: %s, id: %s)" % (e.msg, self.name, resource_id) raise exc.dRestRequestError(msg, e.response) return response
def handle_response(self, response_object): """ A simple wrapper to handle the response. By default raises exc.dRestRequestError if the response code is within 400-499, or 500. Must return the original, or modified, response object. Required Arguments: response_object The response object created by the request. """ response = response_object if (400 <= response.status <= 499) or (response.status == 500): msg = "Received HTTP Code %s - %s" % ( response.status, httplib.responses[int(response.status)]) raise exc.dRestRequestError(msg, response=response) return response
def handle_response(self, response_object): """ A simple wrapper to handle the response. By default raises exc.dRestRequestError if the response code is within 400-499, or 500. Must return the original, or modified, response object. Required Arguments: response_object The response object created by the request. """ response = response_object if (400 <= response.status <=499) or (response.status == 500): msg = "Received HTTP Code %s - %s" % ( response.status, httplib.responses[int(response.status)]) raise exc.dRestRequestError(msg, response=response) return response
def handle_response(self, response, content): """ A simple wrapper to handle the response. By default raises exc.dRestRequestError if the response code is within 400-499, or 500. Required Arguments: response The response object. content The response content. """ if (400 <= response.status <= 499) or (response.status == 500): msg = "Received HTTP Code %s - %s" % (response.status, httplib.responses[int(response.status)]) raise exc.dRestRequestError(msg, response=response, content=content) return (response, content)
def post(self, params={}): """ Create a new resource. Required Arguments: params A dictionary of parameters (different for every resource). """ params = self.filter(params) path = '/%s' % self.path try: response = self.api.make_request('POST', path, self.filter(params)) except exc.dRestRequestError as e: msg = "%s (resource: %s)" % (e.msg, self.name) raise exc.dRestRequestError(msg, e.response) return response