private CartociudadGeocodeResult ValidateGeocodeCandidatesMatch(CartociudadCandidatesResponse candidates, SourceAddress request) { var result = new CartociudadGeocodeResult(); if (candidates == null) { result.Status = AddressStatusType.ZERO_RESULTS.ToString(); return(result); } if (candidates.State != CartociudadState.ValueOne) { result.Status = CartociudadToGeocodeStatusConverter.Convert(candidates.State).ToString(); return(result); } //Check if portal number is ready if (candidates.PortalNumber.Equals(0)) { result.Status = AddressStatusType.TO_CHECK.ToString(); return(result); } if (!candidates.PostalCode.Equals(request.PostalCode)) { result.Status = AddressStatusType.TO_CHECK.ToString(); return(result); } return(result); }
private async Task <CartociudadFindResponse> SelectBestGeocodeAddressMatchAsync(CartociudadCandidatesResponse cartociudadCandidatesResponse) { var streetNumber = cartociudadCandidatesResponse.PortalNumber.ToString(); var result = new CartociudadFindResponse(); using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add( new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/x-javascript")); var response = await client.GetAsync(BuildFindEndPoint(cartociudadCandidatesResponse.Id, streetNumber)); if (response.IsSuccessStatusCode) { string serialized = await response.Content.ReadAsStringAsync(); serialized = serialized.Substring(9, serialized.Length - 9); serialized = serialized.Substring(0, serialized.Length - 1); result = JsonConvert.DeserializeObject <CartociudadFindResponse>(serialized); } else { //var error = await response.Content.ReadAsAsync<ErrorResponse>(); Console.WriteLine("Cartociudad HTTP Error"); result = null; } } return(await Task.FromResult(result)); }
private List <AddressComponent> BuildAddressComponents(CartociudadFindResponse cartociudadFindResponse, CartociudadCandidatesResponse cartociudadCandidatesResponse, SourceAddress sourceAddress) { var result = new List <AddressComponent>(); var component = cartociudadFindResponse.PortalNumber.ToString(); result.Add(BuildAddressComponent <AddressComponent>(STREET_NUMBER, component, component)); component = UpperCaseConverter.Convert(CartoCiudadRouteConverter.Convert(cartociudadFindResponse.Address ?? cartociudadCandidatesResponse.Address, cartociudadFindResponse.PortalNumber.ToString())); result.Add(BuildAddressComponent <AddressComponent>(ROUTE, component, component)); component = UpperCaseConverter.Convert(cartociudadFindResponse.Locality ?? cartociudadCandidatesResponse.Locality); result.Add(BuildAddressComponent <AddressComponent>(LOCALITY, component, component)); component = UpperCaseConverter.Convert(cartociudadFindResponse.Province ?? cartociudadCandidatesResponse.Province); result.Add(BuildAddressComponent <AddressComponent>(ADMINISTRATIVE_AREA_LEVEL_2, component, component)); component = UpperCaseConverter.Convert(CartoCiudadToGeocodeCountryConverter.CountryConvert(cartociudadFindResponse.CountryCode ?? cartociudadCandidatesResponse.CountryCode)); var shortComponent = CartoCiudadToGeocodeCountryConverter.CountryCodeConvert(cartociudadFindResponse.CountryCode ?? cartociudadCandidatesResponse.CountryCode); result.Add(BuildAddressComponent <AddressComponent>(COUNTRY, shortComponent, component)); component = (cartociudadFindResponse.PostalCode == null ? sourceAddress.PostalCode : string.Empty).ToString(); result.Add(BuildAddressComponent <AddressComponent>(POSTAL_CODE, component, component)); return(result); }
private CartociudadGeocodeResult CartociudadAddressToGeocodeAddressResponse(CartociudadFindResponse cartociudadFindResponse, CartociudadCandidatesResponse cartociudadCandidatesResponse, SourceAddress sourceAddress) { var result = new CartociudadGeocodeResult(); var addressComponents = BuildAddressComponents(cartociudadFindResponse, cartociudadCandidatesResponse, sourceAddress); var formatedAddress = BuildFormattedAddress(addressComponents); var placeId = BuildPlaceId(cartociudadFindResponse); result.Results = new List <Result>() { new Result() { AddressComponents = addressComponents, FormattedAddress = formatedAddress, PlaceId = placeId, Types = new List <string>() { STREET_ADDRESS } } }; result.Status = BuildStatus(cartociudadFindResponse); return(result); }