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_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
        quargs = urllib.urlencode(kwargs)
        if quargs:
            quargs = '?'+quargs
        endpoint = self._endpoint('search_by_ip', ipaddr=ipaddr, quargs=quargs)

        result = self._request(endpoint, 'GET')[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
        quargs = urllib.urlencode(kwargs)
        if quargs:
            quargs = '?'+quargs
        endpoint = self._endpoint('search_by_my_ip', quargs=quargs)

        result = self._request(endpoint, 'GET')[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
        quargs = urllib.urlencode(kwargs)
        if quargs:
            quargs = '?'+quargs
        endpoint = self._endpoint('search', lat=lat, lon=lon, quargs=quargs)

        result = self._request(endpoint, 'GET')[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_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', address=urllib.quote_plus(address))
     return json_decode(self._request(endpoint, "GET")[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 recordAddUpdate(self, record):
        """Create a new feature, returns the simplegeohandle. """

        endpoint = self._endpoint('create', layer=record.layer, id=record.id)
        if DEBUG:
            print("Endpoint:\n%s\n" % endpoint);

        jsonrec = record.to_json()
        if DEBUG:
            print("JSON payload:\n%s\n" % jsonrec);

        resp, content = self._request(endpoint, "PUT", jsonrec)
        if resp['status'] != "202":
            raise APIError(int(resp['status']), content, resp)
        contentobj = json_decode(content)
        if DEBUG:
            print("Response:\n%s\n" %contentobj)
    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
        quargs = urllib.urlencode(kwargs)
        endpoint = self._endpoint('search_by_address', quargs=quargs)

        result = self._request(endpoint, 'GET')[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."""
        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)

        kwargs = {}
        if radius:
            kwargs["radius"] = radius
        if query:
            kwargs["q"] = query
        if category:
            kwargs["category"] = category
        quargs = urllib.urlencode(kwargs)
        if quargs:
            quargs = "?" + quargs
        endpoint = self._endpoint("search", lat=lat, lon=lon, quargs=quargs)

        result = self._request(endpoint, "GET")[1]

        fc = json_decode(result)
        return [Feature.from_dict(f) for f in fc["features"]]
 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_context_result(self, rpc):
     result = rpc.get_result()
     if not 200 <= result.status_code < 400:
         raise APIError(result.status_code, result.content, self.headers)
     return json_decode(result.content)