Esempio n. 1
0
 def delete_feature(self, simplegeohandle):
     """Delete a Places feature."""
     if not is_simplegeohandle(simplegeohandle):
         raise ValueError("simplegeohandle is required to match "
                          "the regex %s" % SIMPLEGEOHANDLE_RSTR)
     endpoint = self._endpoint('feature', simplegeohandle=simplegeohandle)
     return self._request(endpoint, 'DELETE')[1]
Esempio n. 2
0
 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
Esempio n. 3
0
 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]
Esempio n. 4
0
 def get_annotations(self, simplegeohandle):
     if not is_simplegeohandle(simplegeohandle):
         raise TypeError(
             "simplegeohandle is required to match the regex %s, but it was %s :: %r"
             % (SIMPLEGEOHANDLE_RSTR, type(simplegeohandle), simplegeohandle)
         )
     endpoint = self._endpoint("annotations", simplegeohandle=simplegeohandle)
     return json_decode(self._request(endpoint, "GET")[1])
Esempio n. 5
0
 def get_annotations(self, simplegeohandle):
     if not is_simplegeohandle(simplegeohandle):
         raise TypeError(
             "simplegeohandle is required to match the regex %s, but it was %s :: %r"
             %
             (SIMPLEGEOHANDLE_RSTR, type(simplegeohandle), simplegeohandle))
     endpoint = self._endpoint('annotations',
                               simplegeohandle=simplegeohandle)
     return json_decode(self._request(endpoint, 'GET')[1])
Esempio n. 6
0
 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
Esempio n. 7
0
 def get_feature(self, simplegeohandle, zoom=None):
     """Return the GeoJSON representation of a feature. Zoom needs to be
     between 1-20, or None for the full polygon."""
     if not is_simplegeohandle(simplegeohandle):
         raise TypeError("simplegeohandle is required to match the regex %s, but it was %s :: %r" % (SIMPLEGEOHANDLE_RSTR, type(simplegeohandle), simplegeohandle))
     kwargs = {}
     if zoom:
         precondition(zoom >= 1 and zoom <= 20, zoom)
         kwargs['zoom'] = zoom
     endpoint = self._endpoint('feature', simplegeohandle=simplegeohandle)
     return Feature.from_json(self._request(endpoint, 'GET', data=kwargs)[1])
Esempio n. 8
0
 def get_feature(self, simplegeohandle, zoom=None):
     """Return the GeoJSON representation of a feature. Zoom needs to be
     between 1-20, or None for the full polygon."""
     if not is_simplegeohandle(simplegeohandle):
         raise TypeError(
             "simplegeohandle is required to match the regex %s, but it was %s :: %r"
             % (SIMPLEGEOHANDLE_RSTR, type(simplegeohandle), simplegeohandle)
         )
     kwargs = {}
     if zoom:
         if zoom < 1 or zoom > 20:
             raise AssertionError("Zoom must be in the range 1..20")
         kwargs["zoom"] = zoom
     endpoint = self._endpoint("feature", simplegeohandle=simplegeohandle)
     return Feature.from_json(self._request(endpoint, "GET", data=kwargs)[1])
Esempio n. 9
0
 def get_feature(self, simplegeohandle, zoom=None):
     """Return the GeoJSON representation of a feature. Zoom needs to be
     between 1-20, or None for the full polygon."""
     if not is_simplegeohandle(simplegeohandle):
         raise TypeError(
             "simplegeohandle is required to match the regex %s, but it was %s :: %r"
             %
             (SIMPLEGEOHANDLE_RSTR, type(simplegeohandle), simplegeohandle))
     kwargs = {}
     if zoom:
         precondition(zoom >= 1 and zoom <= 20, zoom)
         kwargs['zoom'] = zoom
     endpoint = self._endpoint('feature', simplegeohandle=simplegeohandle)
     return Feature.from_json(
         self._request(endpoint, 'GET', data=kwargs)[1])
Esempio n. 10
0
 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]