def add_feature(self, feature): """Create a new feature, returns the simplegeohandle. """ endpoint = self._endpoint('create') if feature.id: # only simplegeohandles or None should be stored in self.id assert is_simplegeohandle(feature.id) raise ValueError('A feature cannot be added to the Places database when it already has a simplegeohandle: %s' % (feature.id,)) jsonrec = feature.to_json() resp, content = self._request(endpoint, "POST", jsonrec) if resp['status'] != "202": raise APIError(int(resp['status']), content, resp) contentobj = json_decode(content) if not contentobj.has_key('id'): raise APIError(int(resp['status']), content, resp) handle = contentobj['id'] assert is_simplegeohandle(handle) return handle
def delete_feature(self, simplegeohandle): """Delete a Places feature.""" precondition( is_simplegeohandle(simplegeohandle), "simplegeohandle is required to match the regex %s" % SIMPLEGEOHANDLE_RSTR, simplegeohandle=simplegeohandle, ) endpoint = self._endpoint("feature", simplegeohandle=simplegeohandle) return self._request(endpoint, "DELETE")[1]