def search_by_ip(self, ipaddr, radius=None, query=None, category=None): """ Search for places near an IP address, within a radius (in kilometers). The server uses guesses the latitude and longitude from the ipaddr and then does the same thing as search(), using that guessed latitude and longitude. """ precondition(is_valid_ip(ipaddr), ipaddr) precondition(radius is None or is_numeric(radius), radius) precondition(query is None or isinstance(query, basestring), query) precondition(category is None or isinstance(category, basestring), category) if isinstance(query, unicode): query = query.encode('utf-8') if isinstance(category, unicode): category = category.encode('utf-8') kwargs = {} if radius: kwargs['radius'] = radius if query: kwargs['q'] = query if category: kwargs['category'] = category endpoint = self._endpoint('search_by_ip', ipaddr=ipaddr) result = self._request(endpoint, 'GET', data=kwargs)[1] fc = json_decode(result) return [Feature.from_dict(f) for f in fc['features']]
def get_context_by_ip(self, ipaddr): """ The server uses guesses the latitude and longitude from the ipaddr and then does the same thing as get_context(), using that guessed latitude and longitude.""" precondition(is_valid_ip(ipaddr), ipaddr) endpoint = self._endpoint('context_by_ip', ip=ipaddr) return json_decode(self._request(endpoint, "GET")[1])
def search(self, lat, lon, radius=None, query=None, category=None): """Search for places near a lat/lon, within a radius (in kilometers).""" precondition(is_valid_lat(lat), lat) precondition(is_valid_lon(lon), lon) precondition(radius is None or is_numeric(radius), radius) precondition(query is None or isinstance(query, basestring), query) precondition(category is None or isinstance(category, basestring), category) if isinstance(query, unicode): query = query.encode('utf-8') if isinstance(category, unicode): category = category.encode('utf-8') kwargs = {} if radius: kwargs['radius'] = radius if query: kwargs['q'] = query if category: kwargs['category'] = category endpoint = self._endpoint('search', lat=lat, lon=lon) result = self._request(endpoint, 'GET', data=kwargs)[1] fc = json_decode(result) return [Feature.from_dict(f) for f in fc['features']]
def search_by_my_ip(self, radius=None, query=None, category=None): """ Search for places near your IP address, within a radius (in kilometers). The server gets the IP address from the HTTP connection (this may be the IP address of your device or of a firewall, NAT, or HTTP proxy device between you and the server), and then does the same thing as search_by_ip(), using that IP address. """ precondition(radius is None or is_numeric(radius), radius) precondition(query is None or isinstance(query, basestring), query) precondition(category is None or isinstance(category, basestring), category) if isinstance(query, unicode): query = query.encode('utf-8') if isinstance(category, unicode): category = category.encode('utf-8') kwargs = {} if radius: kwargs['radius'] = radius if query: kwargs['q'] = query if category: kwargs['category'] = category endpoint = self._endpoint('search_by_my_ip') result = self._request(endpoint, 'GET', data=kwargs)[1] fc = json_decode(result) return [Feature.from_dict(f) for f in fc['features']]
def search(self, lat, lon, radius=None, query=None, category=None, num=None): """Search for places near a lat/lon, within a radius (in kilometers).""" _assert_valid_lat(lat) _assert_valid_lon(lon) if (radius and not is_numeric(radius)): raise ValueError("Radius must be numeric.") if (query and not isinstance(query, basestring)): raise ValueError("Query must be a string.") if (category and not isinstance(category, basestring)): raise ValueError("Category must be a string.") if (num and not is_numeric(num)): raise ValueError("Num parameter must be numeric.") if isinstance(query, unicode): query = query.encode('utf-8') if isinstance(category, unicode): category = category.encode('utf-8') kwargs = { } if radius: kwargs['radius'] = radius if query: kwargs['q'] = query if category: kwargs['category'] = category if num: kwargs['num'] = num endpoint = self._endpoint('search', lat=lat, lon=lon) result = self._request(endpoint, 'GET', data=kwargs)[1] fc = json_decode(result) return [Feature.from_dict(f) for f in fc['features']]
def search(self, lat, lon, radius=None, query=None, category=None): """Search for places near a lat/lon, within a radius (in kilometers).""" precondition(is_valid_lat(lat), lat) precondition(is_valid_lon(lon), lon) precondition(radius is None or is_numeric(radius), radius) precondition(query is None or isinstance(query, basestring), query) precondition(category is None or isinstance(category, basestring), category) if isinstance(query, unicode): query = query.encode('utf-8') if isinstance(category, unicode): category = category.encode('utf-8') kwargs = { } if radius: kwargs['radius'] = radius if query: kwargs['q'] = query if category: kwargs['category'] = category endpoint = self._endpoint('search', lat=lat, lon=lon) result = self._request(endpoint, 'GET', data=kwargs)[1] fc = json_decode(result) return [Feature.from_dict(f) for f in fc['features']]
def __init__(self, body, headers): try: body = json_decode(body) except DecodeError: body = {} dict.__init__(self, body) self.headers = headers
def search_by_my_ip(self, radius=None, query=None, category=None): """ Search for places near your IP address, within a radius (in kilometers). The server gets the IP address from the HTTP connection (this may be the IP address of your device or of a firewall, NAT, or HTTP proxy device between you and the server), and then does the same thing as search_by_ip(), using that IP address. """ precondition(radius is None or is_numeric(radius), radius) precondition(query is None or isinstance(query, basestring), query) precondition(category is None or isinstance(category, basestring), category) if isinstance(query, unicode): query = query.encode('utf-8') if isinstance(category, unicode): category = category.encode('utf-8') kwargs = { } if radius: kwargs['radius'] = radius if query: kwargs['q'] = query if category: kwargs['category'] = category endpoint = self._endpoint('search_by_my_ip') result = self._request(endpoint, 'GET', data=kwargs)[1] fc = json_decode(result) return [Feature.from_dict(f) for f in fc['features']]
def search_by_ip(self, ipaddr, radius=None, query=None, category=None): """ Search for places near an IP address, within a radius (in kilometers). The server uses guesses the latitude and longitude from the ipaddr and then does the same thing as search(), using that guessed latitude and longitude. """ precondition(is_valid_ip(ipaddr), ipaddr) precondition(radius is None or is_numeric(radius), radius) precondition(query is None or isinstance(query, basestring), query) precondition(category is None or isinstance(category, basestring), category) if isinstance(query, unicode): query = query.encode('utf-8') if isinstance(category, unicode): category = category.encode('utf-8') kwargs = { } if radius: kwargs['radius'] = radius if query: kwargs['q'] = query if category: kwargs['category'] = category endpoint = self._endpoint('search_by_ip', ipaddr=ipaddr) result = self._request(endpoint, 'GET', data=kwargs)[1] fc = json_decode(result) return [Feature.from_dict(f) for f in fc['features']]
def get_context_by_my_ip(self): """ The server gets the IP address from the HTTP connection (this may be the IP address of your device or of a firewall, NAT, or HTTP proxy device between you and the server), and then does the same thing as get_context_by_ip(), using that IP address.""" endpoint = self._endpoint('context_by_my_ip') return json_decode(self._request(endpoint, "GET")[1])
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])
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])
def get_context_by_address(self, address): """ The server figures out the latitude and longitude from the street address and then does the same thing as get_context(), using that deduced latitude and longitude. """ precondition(isinstance(address, basestring), address) endpoint = self._endpoint('context_by_address') return json_decode(self._request(endpoint, "GET", data={'address' : address})[1])
def get_context_by_address(self, address): """ The server figures out the latitude and longitude from the street address and then does the same thing as get_context(), using that deduced latitude and longitude. """ precondition(isinstance(address, basestring), address) endpoint = self._endpoint('context_by_address') return json_decode( self._request(endpoint, "GET", data={'address': address})[1])
def get_context(self, lat, lon, filter=None, context_args=None): _assert_valid_lat(lat) _assert_valid_lon(lon) if filter and not isinstance(filter, basestring): raise ValueError("Query must be a string.") kwargs = self._prepare_kwargs(filter=filter, context_args=context_args) endpoint = self._endpoint("context", lat=lat, lon=lon) result = self._request(endpoint, "GET", data=kwargs)[1] return json_decode(result)
def get_context(self, lat, lon, filter=None): _assert_valid_lat(lat) _assert_valid_lon(lon) if (filter and not isinstance(filter, basestring)): raise ValueError("Query must be a string.") kwargs = { } if filter: kwargs['filter'] = filter endpoint = self._endpoint('context', lat=lat, lon=lon) result = self._request(endpoint, 'GET', data=kwargs)[1] return json_decode(result)
def get_context_by_ip(self, ipaddr, filter=None, context_args=None): """ The server uses guesses the latitude and longitude from the ipaddr and then does the same thing as get_context(), using that guessed latitude and longitude.""" if not is_valid_ip(ipaddr): raise ValueError("Address %s is not a valid IP" % ipaddr) if filter and not isinstance(filter, basestring): raise ValueError("Query must be a string.") kwargs = self._prepare_kwargs(filter=filter, context_args=context_args) endpoint = self._endpoint("context_by_ip", ip=ipaddr) result = self._request(endpoint, "GET", data=kwargs)[1] return json_decode(result)
def get_context_by_my_ip(self, filter=None, context_args=None): """ The server gets the IP address from the HTTP connection (this may be the IP address of your device or of a firewall, NAT, or HTTP proxy device between you and the server), and then does the same thing as get_context_by_ip(), using that IP address.""" if filter and not isinstance(filter, basestring): raise ValueError("Query must be a string.") kwargs = self._prepare_kwargs(filter=filter, context_args=context_args) endpoint = self._endpoint("context_by_my_ip") result = self._request(endpoint, "GET", data=kwargs)[1] return json_decode(result)
def annotate(self, simplegeohandle, annotations, private): if not isinstance(annotations, dict): raise TypeError("annotations must be of type dict") if not len(annotations.keys()): raise ValueError("annotations dict is empty") for annotation_type in annotations.keys(): if not len(annotations[annotation_type].keys()): raise ValueError('annotation type "%s" is empty' % annotation_type) if not isinstance(private, bool): raise TypeError("private must be of type bool") data = {"annotations": annotations, "private": private} endpoint = self._endpoint("annotations", simplegeohandle=simplegeohandle) return json_decode(self._request(endpoint, "POST", data=json.dumps(data))[1])
def get_context_by_address(self, address, filter=None, context_args=None): """ The server figures out the latitude and longitude from the street address and then does the same thing as get_context(), using that deduced latitude and longitude. """ if not isinstance(address, basestring): raise ValueError("Address must be a string.") if filter and not isinstance(filter, basestring): raise ValueError("Query must be a string.") kwargs = self._prepare_kwargs(address=address, filter=filter, context_args=context_args) endpoint = self._endpoint("context_by_address") result = self._request(endpoint, "GET", data=kwargs)[1] return json_decode(result)
def get_context_from_bbox(self, sw_lat, sw_lon, ne_lat, ne_lon, **kwargs): """ This function takes a bbox and returns all features that overlap that bounding box. Category uses the format: categorytype__Name. Note the double underscore. Ex: category__Neighborhood or type__Public%20Place Note that we do NOT use the GeoJSON ordering in our API URLs, just responses, so the order here is (minlat, minlon, maxlat, maxlon). """ kwargs = self._prepare_kwargs(context_args=kwargs) endpoint = self._endpoint("context_from_bbox", sw_lat=sw_lat, sw_lon=sw_lon, ne_lat=ne_lat, ne_lon=ne_lon) result = self._request(endpoint, "GET", data=kwargs)[1] return json_decode(result)
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 annotate(self, simplegeohandle, annotations, private): if not isinstance(annotations, dict): raise TypeError('annotations must be of type dict') if not len(annotations.keys()): raise ValueError('annotations dict is empty') for annotation_type in annotations.keys(): if not len(annotations[annotation_type].keys()): raise ValueError('annotation type "%s" is empty' % annotation_type) if not isinstance(private, bool): raise TypeError('private must be of type bool') data = {'annotations': annotations, 'private': private} endpoint = self._endpoint('annotations', simplegeohandle=simplegeohandle) return json_decode( self._request(endpoint, 'POST', data=json.dumps(data))[1])
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 search_by_address(self, address, radius=None, query=None, category=None, num=None): """ Search for places near the given address, within a radius (in kilometers). The server figures out the latitude and longitude from the street address and then does the same thing as search(), using that deduced latitude and longitude. """ if not isinstance(address, basestring) or not address.strip(): raise ValueError("Address must be a non-empty string.") if (radius and not is_numeric(radius)): raise ValueError("Radius must be numeric.") if (query and not isinstance(query, basestring)): raise ValueError("Query must be a string.") if (category and not isinstance(category, basestring)): raise ValueError("Category must be a string.") if (num and not is_numeric(num)): raise ValueError("Num parameter must be numeric.") if isinstance(address, unicode): address = address.encode('utf-8') if isinstance(query, unicode): query = query.encode('utf-8') if isinstance(category, unicode): category = category.encode('utf-8') kwargs = { 'address': address } if radius: kwargs['radius'] = radius if query: kwargs['q'] = query if category: kwargs['category'] = category if num: kwargs['num'] = num endpoint = self._endpoint('search_by_address') result = self._request(endpoint, 'GET', data=kwargs)[1] fc = json_decode(result) return [Feature.from_dict(f) for f in fc['features']]
def search_by_address(self, address, radius=None, query=None, category=None): """ Search for places near the given address, within a radius (in kilometers). The server figures out the latitude and longitude from the street address and then does the same thing as search(), using that deduced latitude and longitude. """ precondition(isinstance(address, basestring), address) precondition(address != '', address) precondition(radius is None or is_numeric(radius), radius) precondition(query is None or isinstance(query, basestring), query) precondition(category is None or isinstance(category, basestring), category) if isinstance(address, unicode): address = address.encode('utf-8') if isinstance(query, unicode): query = query.encode('utf-8') if isinstance(category, unicode): category = category.encode('utf-8') kwargs = {'address': address} if radius: kwargs['radius'] = radius if query: kwargs['q'] = query if category: kwargs['category'] = category endpoint = self._endpoint('search_by_address') result = self._request(endpoint, 'GET', data=kwargs)[1] fc = json_decode(result) return [Feature.from_dict(f) for f in fc['features']]
def search_by_ip(self, ipaddr, radius=None, query=None, category=None, num=None): """ Search for places near an IP address, within a radius (in kilometers). The server uses guesses the latitude and longitude from the ipaddr and then does the same thing as search(), using that guessed latitude and longitude. """ if not is_valid_ip(ipaddr): raise ValueError("Address %s is not a valid IP" % ipaddr) if (radius and not is_numeric(radius)): raise ValueError("Radius must be numeric.") if (query and not isinstance(query, basestring)): raise ValueError("Query must be a string.") if (category and not isinstance(category, basestring)): raise ValueError("Category must be a string.") if (num and not is_numeric(num)): raise ValueError("Num parameter must be numeric.") if isinstance(query, unicode): query = query.encode('utf-8') if isinstance(category, unicode): category = category.encode('utf-8') kwargs = { } if radius: kwargs['radius'] = radius if query: kwargs['q'] = query if category: kwargs['category'] = category if num: kwargs['num'] = num endpoint = self._endpoint('search_by_ip', ipaddr=ipaddr) result = self._request(endpoint, 'GET', data=kwargs)[1] fc = json_decode(result) return [Feature.from_dict(f) for f in fc['features']]
def get_context_by_address(self, address, filter=None): """ The server figures out the latitude and longitude from the street address and then does the same thing as get_context(), using that deduced latitude and longitude. """ if not isinstance(address, basestring): raise ValueError("Address must be a string.") if (filter and not isinstance(filter, basestring)): raise ValueError("Query must be a string.") kwargs = { } if filter: kwargs['filter'] = filter if address: kwargs['address'] = address endpoint = self._endpoint('context_by_address') result = self._request(endpoint, 'GET', data=kwargs)[1] return json_decode(result)
def search_by_my_ip(self, radius=None, query=None, category=None, num=None): """ Search for places near your IP address, within a radius (in kilometers). The server gets the IP address from the HTTP connection (this may be the IP address of your device or of a firewall, NAT, or HTTP proxy device between you and the server), and then does the same thing as search_by_ip(), using that IP address. """ if (radius and not is_numeric(radius)): raise ValueError("Radius must be numeric.") if (query and not isinstance(query, basestring)): raise ValueError("Query must be a string.") if (category and not isinstance(category, basestring)): raise ValueError("Category must be a string.") if (num and not is_numeric(num)): raise ValueError("Num parameter must be numeric.") if isinstance(query, unicode): query = query.encode('utf-8') if isinstance(category, unicode): category = category.encode('utf-8') kwargs = { } if radius: kwargs['radius'] = radius if query: kwargs['q'] = query if category: kwargs['category'] = category if num: kwargs['num'] = num endpoint = self._endpoint('search_by_my_ip') result = self._request(endpoint, 'GET', data=kwargs)[1] fc = json_decode(result) return [Feature.from_dict(f) for f in fc['features']]
def search_by_address(self, address, radius=None, query=None, category=None): """ Search for places near the given address, within a radius (in kilometers). The server figures out the latitude and longitude from the street address and then does the same thing as search(), using that deduced latitude and longitude. """ precondition(isinstance(address, basestring), address) precondition(address != '', address) precondition(radius is None or is_numeric(radius), radius) precondition(query is None or isinstance(query, basestring), query) precondition(category is None or isinstance(category, basestring), category) if isinstance(address, unicode): address = address.encode('utf-8') if isinstance(query, unicode): query = query.encode('utf-8') if isinstance(category, unicode): category = category.encode('utf-8') kwargs = { 'address': address } if radius: kwargs['radius'] = radius if query: kwargs['q'] = query if category: kwargs['category'] = category endpoint = self._endpoint('search_by_address') result = self._request(endpoint, 'GET', data=kwargs)[1] fc = json_decode(result) return [Feature.from_dict(f) for f in fc['features']]
def get_nearby(self, layer, lat, lon, **kwargs): endpoint = self._endpoint('nearby', layer=layer, arg='%s,%s' % (lat, lon)) return json_decode(self._request(endpoint, "GET", data=kwargs)[1])
def get_history(self, layer, id, **kwargs): endpoint = self._endpoint('history', layer=layer, id=id) return json_decode(self._request(endpoint, "GET", data=kwargs)[1])
def get_records(self, layer, ids): endpoint = self._endpoint('records', layer=layer, ids=','.join(ids)) features = json_decode(self._request(endpoint, "GET")[1]) return features.get('features') or []
def get_record(self, layer, id): endpoint = self._endpoint('record', layer=layer, id=id) return json_decode(self._request(endpoint, "GET")[1])
def delete_layer(self, name): endpoint = self._endpoint('layer', layer=name) return json_decode(self._request(endpoint, "DELETE")[1])
def get_layer(self, name): endpoint = self._endpoint('layer', layer=name) return json_decode(self._request(endpoint, "GET")[1])
def create_layer(self, layer): endpoint = self._endpoint('layer', layer=layer.name) return json_decode(self._request(endpoint, "PUT", layer.to_json())[1])
def get_context(self, lat, lon): precondition(is_valid_lat(lat), lat) precondition(is_valid_lon(lon), lon) endpoint = self._endpoint('context', lat=lat, lon=lon) return json_decode(self._request(endpoint, "GET")[1])
def get_layers(self, **kwargs): endpoint = self._endpoint('layers') return json_decode(self._request(endpoint, "GET", data=kwargs)[1])
def get_layers(self): endpoint = self._endpoint('layers') return json_decode(self._request(endpoint, "GET")[1])