Skip to content

Instantly share code, notes, and snippets.

@ChrisBriggsy
Last active September 8, 2015 10:28
Show Gist options
  • Save ChrisBriggsy/2dd0e442885ff744cbb5 to your computer and use it in GitHub Desktop.
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
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