예제 #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
예제 #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
예제 #3
0
파일: http.py 프로젝트: stephcyrille/cubane
 def test_wget_404(self):
     response = wget('http://httpbin.org/404')
     self.assertEqual(response.code, 404)
예제 #4
0
파일: http.py 프로젝트: stephcyrille/cubane
 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')
예제 #5
0
파일: http.py 프로젝트: stephcyrille/cubane
 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)