예제 #1
0
 def make_request(self, **kwargs):
     """Makes http request to geocoding services and process the payloads."""
     if 'address' not in kwargs:
         lat_long = models.LatitudeLongitude()
         lat_long.add_error(400, constants.MISSING_QUERY_PARAM)
         return lat_long
     r = self.prepare_request(**kwargs)
     return self.process_payload(r.json())
예제 #2
0
 def process_payload(self, json_object):
     """Returns the instance of the LatitudeLongitude instance."""
     response_object = json_object.get('Response', {})
     view_object_list = response_object.get('View', [])
     result_object_list = view_object_list[0].get('Result', [])
     location = result_object_list[0].get('Location', {})
     navigation_position_list = location.get('NavigationPosition', [])
     return models.LatitudeLongitude(
         navigation_position_list[0].get('Latitude'),
         navigation_position_list[0].get('Longitude'))
예제 #3
0
def fetch_geocoding_information(**kwargs):
    """Returns the geocoding information from either the geocoding services."""
    all_services = [GoogleMapGeocoding(), HereEncodingService()]
    lat_long = None
    for service in all_services:
        lat_long = service.make_request(**kwargs)
        if lat_long and not lat_long.errors:
            return lat_long
    lat_long = models.LatitudeLongitude()
    lat_long.add_error(400, _NO_DATA_FOUND)
    return lat_long
예제 #4
0
def test_fetch_geocoding_information__failure():
    lat_long_error = http_helper.fetch_geocoding_information()
    lat_long_expected = models.LatitudeLongitude()
    lat_long_expected.add_error(400, http_helper._NO_DATA_FOUND)
    assert lat_long_error == lat_long_expected
예제 #5
0
def test_fetch_geocoding_information__success():
    lat_long = http_helper.fetch_geocoding_information(
        address='1600+Amphitheatre+Parkway+Mountain+View')
    assert lat_long == (models.LatitudeLongitude(latitude=37.4261881,
                                                 longitude=-122.0761534))
예제 #6
0
 def test_make_request(self):
     latitude_longitude = self.google_maps_service.make_request(
         address='1600+Amphitheatre+Parkway+Mountain+View')
     assert latitude_longitude == (models.LatitudeLongitude(
         latitude=37.4261881, longitude=-122.0761534))
예제 #7
0
 def test_make_request(self):
     latitude_longitude = self.here_encoding_service.make_request(
         address='1600+Amphitheatre+Parkway+Mountain+View')
     assert latitude_longitude == (models.LatitudeLongitude(
         latitude=37.42307, longitude=-122.08414))
예제 #8
0
 def process_payload(self, json_object):
     result_object_list = json_object.get('results', [])
     geometry = result_object_list[0].get('geometry', {})
     location = geometry.get('location', {})
     return models.LatitudeLongitude(location.get('lat'),
                                     location.get('lng'))
예제 #9
0
def create_error(error_code, error_message):
    """Creates an error representation for the latitude and longitude object."""
    lat_long = models.LatitudeLongitude()
    lat_long.add_error(error_code, error_message)
    return lat_long