static string _host = "https://astuteincservices.com";
A method named LogMeIn() returns an instance of DGLogInRequest with your credentials.
static void TurnOnOffHub(string token)
{
HttpClient apiClient = new HttpClient();
string route = "/api/hub";
var json = JsonConvert.SerializeObject(LogMeIn());
var strContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
apiClient.DefaultRequestHeaders.Clear();
apiClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
DateTime onDate = new DateTime(2018, 4, 1, 13, 45, 30);
DateTime offDate = new DateTime(2018, 12, 31);
var fullData = new DGOnOffWithLoginRequest
{
LoginRequest = LogMeIn(),
OnHubDate = onDate,
OffHubDate = offDate
};
json = JsonConvert.SerializeObject(fullData);
strContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
var response = apiClient.PostAsync(_host + route + "/TurnOnOff/352753091969608", strContent).Result;
Console.WriteLine(response.StatusCode);
var reply = response.Content.ReadAsStringAsync().Result;
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
if (!reply.StartsWith("ERROR:"))
Console.WriteLine("Hub Turned On and OFf");
else
Console.WriteLine(reply);
}
else
{
Console.WriteLine("-------------------");
Console.WriteLine(reply);
}
}
static void FlurlTurnOnOffHub(string token)
{
DateTime onDate = new DateTime(2018, 4, 1, 13, 45, 30);
DateTime offDate = new DateTime(2018, 12, 31);
var fullData = new DGOnOffWithLoginRequest
{
LoginRequest = LogMeIn(),
OnHubDate = onDate,
OffHubDate = offDate
};
var response = _host.AppendPathSegment("/api/hub/TurnOnOff/352753091969608").WithOAuthBearerToken(token).PostJsonAsync(fullData).Result;
Console.WriteLine(response.StatusCode);
var reply = response.Content.ReadAsStringAsync().Result;
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
if (!reply.StartsWith("ERROR:"))
Console.WriteLine("Hub Turned On and OFf");
else
Console.WriteLine(reply);
}
else
{
Console.WriteLine("-------------------");
Console.WriteLine(reply);
}
}