2024-02-11 22:57:23 +01:00
|
|
|
|
using CShocker.Devices.Abstract;
|
2024-01-29 15:37:19 +01:00
|
|
|
|
using CShocker.Devices.Additional;
|
|
|
|
|
using CShocker.Shockers;
|
|
|
|
|
using CShocker.Shockers.Abstract;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
2024-02-01 23:03:28 +01:00
|
|
|
|
namespace CShocker.Devices.APIs;
|
2024-01-29 15:37:19 +01:00
|
|
|
|
|
2024-02-01 23:03:28 +01:00
|
|
|
|
public class OpenShockHttp : OpenShockApi
|
2024-01-29 15:37:19 +01:00
|
|
|
|
{
|
2024-02-01 23:03:28 +01:00
|
|
|
|
protected override void ControlInternal(ControlAction action, Shocker shocker, int intensity, int duration)
|
2024-01-29 15:37:19 +01:00
|
|
|
|
{
|
|
|
|
|
if (shocker is not OpenShockShocker openShockShocker)
|
|
|
|
|
{
|
|
|
|
|
this.Logger?.Log(LogLevel.Warning, $"Shocker {shocker} is not {typeof(OpenShockShocker).FullName}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-11 22:57:23 +01:00
|
|
|
|
string json = "{" +
|
|
|
|
|
" \"shocks\": [" +
|
|
|
|
|
" {" +
|
2024-02-12 02:03:35 +01:00
|
|
|
|
$" \"id\": \"{openShockShocker.ID}\"," +
|
2024-11-03 01:11:33 +01:00
|
|
|
|
$" \"type\": \"{Enum.GetName(action)}\"," +
|
2024-02-11 22:57:23 +01:00
|
|
|
|
$" \"intensity\": {intensity}," +
|
|
|
|
|
$" \"duration\": {duration}" +
|
|
|
|
|
" }" +
|
|
|
|
|
" ]," +
|
|
|
|
|
" \"customName\": \"CShocker\"" +
|
|
|
|
|
"}";
|
|
|
|
|
|
|
|
|
|
ApiHttpClient.MakeAPICall(HttpMethod.Post, $"{Endpoint}/2/shockers/control", json, this.Logger, new ValueTuple<string, string>("OpenShockToken", ApiKey));
|
2024-01-29 15:37:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-11 22:24:53 +01:00
|
|
|
|
public OpenShockHttp(string apiKey, string endpoint = "https://api.shocklink.net", ILogger? logger = null) : base(DeviceApi.OpenShockHttp, apiKey, endpoint, logger)
|
2024-01-29 15:37:19 +01:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|