public static async Task <weather_data.RootObject> requestWeather() { initClient(); location_data current_location = await requestLocation(); string url = "http://api.openweathermap.org/data/2.5/weather"; url += $"?lat={ current_location.latitude }&lon={ current_location.longitude }"; url += $"&appid={API_key}"; using (HttpResponseMessage respond = await Client.GetAsync(url)) { if (respond.IsSuccessStatusCode) { weather_data.RootObject data = await respond.Content. ReadAsAsync <weather_data.RootObject>(); return(data); } else { throw new Exception("Please check your internet\n"); } } }
public static async Task <location_data> requestLocation() { initClient(); string ip_address = await requestIP(); string url = $"https://api.ipdata.co/{ip_address}" + $"?api-key=5eda9e6bd49b361f4bf8f23a85d3b57692ba0c963f8132c9460c4bf9"; using (HttpResponseMessage respond = await Client.GetAsync(url)) { if (respond.IsSuccessStatusCode) { location_data data = await respond.Content. ReadAsAsync <location_data>(); return(data); } else { throw new Exception("Please check your internet\n"); } } }