37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
|
|
using System;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using System.Threading.Tasks;
|
|
using System.Text.Json;
|
|
using Microsoft.Extensions.Configuration;
|
|
namespace Inventory.Core
|
|
{
|
|
public class SlurpitClient
|
|
{
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
|
|
public SlurpitClient(IHttpClientFactory httpClientFactory)
|
|
{
|
|
_httpClientFactory = httpClientFactory;
|
|
}
|
|
|
|
public async Task SendDeviceData(Device deviceData)
|
|
{
|
|
var slurpitUrl = Secrets.SlurpitUrl;
|
|
var slurpitApiKey = Secrets.SlurpitApiKey;
|
|
|
|
if (string.IsNullOrWhiteSpace(slurpitUrl) || string.IsNullOrWhiteSpace(slurpitApiKey))
|
|
{
|
|
// Don't send if not configured
|
|
return;
|
|
}
|
|
|
|
var client = _httpClientFactory.CreateClient();
|
|
client.DefaultRequestHeaders.Add("Authorization", $"ApiKey {slurpitApiKey}");
|
|
|
|
await client.PostAsJsonAsync(slurpitUrl, deviceData);
|
|
}
|
|
}
|
|
}
|