using System.Net; using Moonlight.App.ApiClients.IpLocate.Resources; using Newtonsoft.Json; namespace Moonlight.App.Services.Sessions; public class IpLocateService { private readonly IdentityService IdentityService; public IpLocateService(IdentityService identityService) { IdentityService = identityService; } public async Task GetLocation() { var ip = IdentityService.GetIp(); var location = "N/A"; if (ip != "N/A") { using (var wc = new WebClient()) { var res = JsonConvert.DeserializeObject( await wc.DownloadStringTaskAsync( $"http://ip-api.com/json/{ip}" ) ); location = $"{res.Country} - {res.RegionName} - {res.City} ({res.Org})"; } } return location; } }