예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public async Task <WeatherObservationsResponse> GetJsonAsync(WeatherWmo wmo)
        {
            if (string.IsNullOrEmpty(Options?.JsonUrl))
            {
                throw new Exception("Cannot find Json Url from settings.");
            }

            var jsonUrl = Options.JsonUrl.Replace("{WMO}", ((int)wmo).ToString());

            using (var wc = new WebClient())
            {
                wc.Headers.Add("User-Agent", "Other");
                var url     = new Uri(jsonUrl);
                var content = wc.DownloadString(url);
                var result  = JsonConvert.DeserializeObject <WeatherObservationsResponse>(content);
                return(await Task.FromResult(result));
            }
        }
예제 #2
0
        public async Task <ActionResult> GetObservations(WeatherWmo stationId, string fields)
        {
            var result = await _service.GetJsonAsync(stationId);

            var records = result?.GetRecords();

            if (!string.IsNullOrEmpty(fields))
            {
                var splitter = ',';
                var expandos = _service.FilterBy(records, fields.Split(splitter));

                var jsonExpandos = JsonConvert.SerializeObject(expandos);
                return(Ok(jsonExpandos));
            }
            else
            {
                var jsonRecords = JsonConvert.SerializeObject(records);
                return(Ok(jsonRecords));
            }
        }