Esempio n. 1
0
        public async Task <ForecastIOResponse> Get()
        {
            var url = (_time == null)
                ? String.Format(CurrentForecastUrl, _apiKey, _latitude, _longitude, _unit, _extend, _exclude)
                : String.Format(PeriodForecastUrl, _apiKey, _latitude, _longitude, _time, _unit, _extend, _exclude);

            using (var httpClient = new HttpClient())
            {
                try
                {
                    var json = await httpClient.GetStringAsync(url);

                    json = RequestHelpers.FormatResponse(json);
                    var serializer = new JavaScriptSerializer();
                    var forecast   = serializer.Deserialize <ForecastIOResponse>(json);
                    return(forecast);
                }
                catch (HttpRequestException ex)
                {
                    Console.WriteLine(ex.Message);
                    return(null);
                }
            }
        }