示例#1
0
        public LocationDTO Map(GeoIpLocationDTO geoIpLocationDTO)
        {
            LocationDTO location = new LocationDTO();

            location.CityName    = geoIpLocationDTO.data.geo.city;
            location.CountryCode = geoIpLocationDTO.data.geo.country_code;

            return(location);
        }
示例#2
0
        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();
            }
        }
示例#3
0
        private bool IsValid(GeoIpLocationDTO geoIpLocationDTO)
        {
            bool isValid = (geoIpLocationDTO != null && !string.IsNullOrEmpty(geoIpLocationDTO.data.geo.city));

            return(isValid);
        }