/// <summary> /// Receives a uri and uses this to download a json file and deserialise it into the custom WeatherData object as an async operation. /// </summary> /// <param name="pwsUri"></param> /// <returns></returns> private async Task<WeatherData> CombinedWeatherDataAsync(Uri pwsUri) { // Download Json data JsonProvider jsonProvider = new JsonProvider(); string jsonData = await jsonProvider.DownloadJsonStringAsync(pwsUri); // Deserialise Json file into custom object JsonDeserializer jsonDeserialize = new JsonDeserializer(); return await jsonDeserialize.JsonToWeatherDataAsync(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)); }
/// <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> /// Receives a uri and uses this to download a json file and deserialise it into the custom WeatherData object as an async operation. /// </summary> /// <param name="pwsUri"></param> /// <returns></returns> private async Task <WeatherData> CombinedWeatherDataAsync(Uri pwsUri) { // Download Json data JsonProvider jsonProvider = new JsonProvider(); string jsonData = await jsonProvider.DownloadJsonStringAsync(pwsUri); // Deserialise Json file into custom object JsonDeserializer jsonDeserialize = new JsonDeserializer(); return(await jsonDeserialize.JsonToWeatherDataAsync(jsonData)); }
public void GivenValidUri_WhenCallingDownloadJsonString_ThenStringFileReturned() { // Arrange bool actualResultValue = false; UriProvider uriProvider = new UriProvider(); Uri testUri = uriProvider.CreateWunUri(WunDataFeatures.astronomy, "INORTHLA43"); JsonProvider jsonProvider = new JsonProvider(); //Act string jsonData = jsonProvider.DownloadJsonString(testUri); if (string.IsNullOrEmpty(jsonData) == true) { actualResultValue = false; } else { actualResultValue = true; } //Assert Assert.IsTrue(actualResultValue); }