public LocationDTO Map(GeoIpLocationDTO geoIpLocationDTO) { LocationDTO location = new LocationDTO(); location.CityName = geoIpLocationDTO.data.geo.city; location.CountryCode = geoIpLocationDTO.data.geo.country_code; return(location); }
public async Task <LocationDTO> FindLocationByIp(string ip) { try { string fullUrl = _ipLocationApiUrl + ip; GeoIpLocationDTO geoIpLocationDTO = await this._genericRestService.Get <GeoIpLocationDTO>(fullUrl); if (!this.IsValid(geoIpLocationDTO)) { throw new NoLocationFoundException(); } LocationDTO locationDTO = this._locationMapper.Map(geoIpLocationDTO); return(locationDTO); } catch (NotFoundException) { throw new NoLocationFoundException(); } }
private bool IsValid(GeoIpLocationDTO geoIpLocationDTO) { bool isValid = (geoIpLocationDTO != null && !string.IsNullOrEmpty(geoIpLocationDTO.data.geo.city)); return(isValid); }