Ejemplo n.º 1
0
        public static async Task <Forecast5d> RunAsync(Coordinates coord)
        {
            string query   = baseURL;
            var    content = new FormUrlEncodedContent(new KeyValuePair <string, string>[] {
                new KeyValuePair <string, string>("lat", coord.Latitude.ToString()),
                new KeyValuePair <string, string>("lon", coord.Longitude.ToString()),
                new KeyValuePair <string, string>("APPID", apiKey),
                new KeyValuePair <string, string>("units", "metric")
            });

            query += content.ReadAsStringAsync().Result;

            Forecast5d forecast = null;

            try
            {
                forecast = await GetForecast5dAsync(query);

                return(forecast);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
Ejemplo n.º 2
0
        static async Task <Forecast5d> GetForecast5dAsync(string path)
        {
            Forecast5d          forecast = null;
            HttpResponseMessage response = client.GetAsync(path).Result;

            if (response.IsSuccessStatusCode)
            {
                forecast = await response.Content.ReadAsAsync <Forecast5d>();
            }
            return(forecast);
        }