Last active
September 8, 2015 10:28
-
-
Save ChrisBriggsy/2dd0e442885ff744cbb5 to your computer and use it in GitHub Desktop.
Setting up Dependency Injection for Windows Universal Platform using Autofac - Step 3 - Create a desktop compatible version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using Newtonsoft.Json; | |
using SparkFun; | |
namespace IoTBackUp | |
{ | |
internal class DesktopWeather : ISparkFunWeatherSheild | |
{ | |
public float Humidity { get; private set; } | |
public float Temperature { get; private set; } | |
public async Task<bool> Setup() | |
{ | |
try | |
{ | |
var httpClient = new HttpClient(); | |
var response = | |
await httpClient.GetAsync("http://api.openweathermap.org/data/2.5/weather?q=Melbourne&units=metric"); | |
var JSONWeatherObj = | |
JsonConvert.DeserializeObject<OpenWeatherMapData>(await response.Content.ReadAsStringAsync()); | |
Humidity = JSONWeatherObj.main.humidity; | |
Temperature = JSONWeatherObj.main.temp; | |
return true; | |
} | |
catch (Exception e) | |
{ | |
return false; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment