예제 #1
0
        public async Task <Location> GetAsync(IPAddress ipAddress, CancellationToken token)
        {
            var query  = new CountryByIpQuery(ipAddress.ToString());
            var result = await _queryBus.QueryAsync(query, token);

            if (result != null)
            {
                var callingCode = _countryProvider.GetCallingCode(result);
                return(new Location(result, callingCode));
            }

            var uri   = new Uri($"http://api.ipstack.com/{ipAddress}?access_key=0b561be1266ad6b1d01f2daedc4703cd");
            var ipDto = await _restClient.GetAsync <IpDto>(uri, null, token);

            if (ipDto == null)
            {
                return(null);
            }

            //if (ipDto.Latitude == null && ipDto.Longitude == null)
            //{
            //    return null;
            //}
            //var address = new Address(ipDto.City, ipDto.RegionCode, ipDto.CountryCode);
            return(new Location(ipDto.CountryCode, ipDto.Location?.CallingCode));
        }
예제 #2
0
 public async Task CountryByIpQuery_Ok()
 {
     var query = new CountryByIpQuery("112.209.166.71");
     var _     = await fixture.QueryBus.QueryAsync(query, default);
 }