2.5.0
Update DefaultEndpoint Update ControlActionEnum.cs
This commit is contained in:
parent
7693aa8b09
commit
ce0a287e4e
@ -7,7 +7,7 @@
|
||||
<Authors>Glax</Authors>
|
||||
<RepositoryUrl>https://github.com/C9Glax/CShocker</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<Version>2.4.2</Version>
|
||||
<Version>2.5.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -20,7 +20,7 @@ public class OpenShockHttp : OpenShockApi
|
||||
" \"shocks\": [" +
|
||||
" {" +
|
||||
$" \"id\": \"{openShockShocker.ID}\"," +
|
||||
$" \"type\": {ControlActionToByte(action)}," +
|
||||
$" \"type\": \"{Enum.GetName(action)}\"," +
|
||||
$" \"intensity\": {intensity}," +
|
||||
$" \"duration\": {duration}" +
|
||||
" }" +
|
||||
@ -31,17 +31,6 @@ public class OpenShockHttp : OpenShockApi
|
||||
ApiHttpClient.MakeAPICall(HttpMethod.Post, $"{Endpoint}/2/shockers/control", json, this.Logger, new ValueTuple<string, string>("OpenShockToken", ApiKey));
|
||||
}
|
||||
|
||||
private byte ControlActionToByte(ControlAction action)
|
||||
{
|
||||
return action switch
|
||||
{
|
||||
ControlAction.Beep => 3,
|
||||
ControlAction.Vibrate => 2,
|
||||
ControlAction.Shock => 1,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
public OpenShockHttp(string apiKey, string endpoint = "https://api.shocklink.net", ILogger? logger = null) : base(DeviceApi.OpenShockHttp, apiKey, endpoint, logger)
|
||||
{
|
||||
}
|
||||
|
@ -20,11 +20,6 @@ public abstract class Api : IDisposable
|
||||
internal void Control(ControlAction action, int intensity, int duration, params Shocker[] shockers)
|
||||
{
|
||||
bool enqueueItem = true;
|
||||
if (action is ControlAction.Nothing)
|
||||
{
|
||||
this.Logger?.Log(LogLevel.Information, "No action defined.");
|
||||
enqueueItem = false;
|
||||
}
|
||||
if (!ValidIntensityRange.IsValueWithinLimits(intensity))
|
||||
{
|
||||
this.Logger?.Log(LogLevel.Information, $"Value not within allowed {nameof(intensity)}-Range ({ValidIntensityRange.RangeString()}): {intensity}");
|
||||
|
@ -11,7 +11,7 @@ public abstract class OpenShockApi : Api
|
||||
// ReSharper disable twice MemberCanBeProtected.Global -> Exposed
|
||||
public string Endpoint { get; init; }
|
||||
public string ApiKey { get; init; }
|
||||
private const string DefaultEndpoint = "https://api.shocklink.net";
|
||||
private const string DefaultEndpoint = "https://api.openshock.app";
|
||||
|
||||
// ReSharper disable once PublicConstructorInAbstractClass -> Exposed
|
||||
public OpenShockApi(DeviceApi apiType, string apiKey, string endpoint = DefaultEndpoint, ILogger? logger = null) : base(apiType, new IntegerRange(0, 100), new IntegerRange(300, 30000), logger)
|
||||
|
@ -18,12 +18,15 @@ public static class ApiHttpClient
|
||||
Headers =
|
||||
{
|
||||
UserAgent = { userAgent },
|
||||
Accept = { new MediaTypeWithQualityHeaderValue("application/json") }
|
||||
Accept = { new MediaTypeWithQualityHeaderValue("application/json") },
|
||||
|
||||
}
|
||||
};
|
||||
if (jsonContent is not null && jsonContent.Length > 0)
|
||||
request.Content =
|
||||
new StringContent(jsonContent, Encoding.UTF8, new MediaTypeHeaderValue("application/json"));
|
||||
request.Content = new ByteArrayContent(Encoding.UTF8.GetBytes(jsonContent))
|
||||
{
|
||||
Headers = { ContentType = MediaTypeHeaderValue.Parse("application/json") }
|
||||
};
|
||||
foreach ((string, string) customHeader in customHeaders)
|
||||
request.Headers.Add(customHeader.Item1, customHeader.Item2);
|
||||
logger?.Log(LogLevel.Debug, string.Join("\n\t",
|
||||
|
@ -5,5 +5,5 @@ public enum ControlAction
|
||||
Beep,
|
||||
Vibrate,
|
||||
Shock,
|
||||
Nothing
|
||||
Stop
|
||||
}
|
Loading…
Reference in New Issue
Block a user