public Uri CreateWunUri(WunDataFeatures dataFeatures, string location) { string wunApiKey = Resources.WundergroundApiKey; Uri baseUri = new Uri("http://api.wunderground.com/api/"); return(new Uri(baseUri, string.Format($"{wunApiKey}/pws/{dataFeatures}/q/pws:{location}.json"))); // Complete uri will look something like: http://api.wunderground.com/api/YourApiKey/pws/conditions/q/pws:ISOUTHLA34.json }
/// <summary> /// Generic method for getting the data features of your choosing as an asynchronous operation. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="location"></param> /// <param name="dataFeatures"></param> /// <returns></returns> public async Task <T> GetDataAsync <T>(PwsGeographicLocation location, WunDataFeatures dataFeatures) where T : IWunData { UriProvider uriProvider = new UriProvider(); string pwsIdentifier = GetPwsIdentifier(location); Uri pwsUri = uriProvider.CreateWunUri(dataFeatures, pwsIdentifier); JsonProvider jsonProvider = new JsonProvider(); string jsonData = await jsonProvider.DownloadJsonStringAsync(pwsUri); return(await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <T>(jsonData))); }
/// <summary> /// Generic method for getting the data features of your choosing as a synchronous operation. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="location"></param> /// <param name="dataFeatures"></param> /// <returns></returns> public T GetData <T>(PwsGeographicLocation location, WunDataFeatures dataFeatures) where T : IWunData { UriProvider uriProvider = new UriProvider(); string pwsIdentifier = GetPwsIdentifier(location); Uri pwsUri = uriProvider.CreateWunUri(dataFeatures, pwsIdentifier); JsonProvider jsonProvider = new JsonProvider(); string jsonData = jsonProvider.DownloadJsonString(pwsUri); return(JsonConvert.DeserializeObject <T>(jsonData)); }