Beispiel #1
0
def geocode(address,
            apikey=settings.CUBANE_GOOGLE_MAP_API_KEY,
            url='https://maps.googleapis.com/maps/api/geocode/json'):
    """
    Make an API call to google's geocoding API and return the raw response
    as JSON based on the given human-readable address.
    """
    response = wget(url, {'address': address, 'key': apikey})

    if response.code == 200:
        return decode_json(response.data)
    else:
        return None
Beispiel #2
0
def reverse_geocode(lat,
                    lng,
                    apikey=settings.CUBANE_GOOGLE_MAP_API_KEY,
                    url='https://maps.googleapis.com/maps/api/geocode/json'):
    """
    Make an API call to google's geocoding API and return the raw response
    as JSON based on the given latitude/longitude coordinates.
    """
    response = wget(url, {'latlng': '%f,%f' % (lat, lng), 'key': apikey})

    if response.code == 200:
        return decode_json(response.data)
    else:
        return None
Beispiel #3
0
 def test_wget_404(self):
     response = wget('http://httpbin.org/404')
     self.assertEqual(response.code, 404)
Beispiel #4
0
 def test_wget_with_args(self):
     response = wget('http://httpbin.org/get', {'foo': 'bar'})
     j = json.loads(response.data)
     self.assertEqual(j.get('args').get('foo'), 'bar')
Beispiel #5
0
 def test_wget_should_download_document(self):
     response = wget('http://httpbin.org/')
     self.assertEqual(response.code, 200)
     self.assertTrue('HTTP Request & Response Service' in response.data)