Skip to content

Commit b6417e2

Browse files
committed
Add root request
1 parent 7e5c40d commit b6417e2

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

SDK.CSharp/IOpenShockApiClient.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,25 @@ public interface IOpenShockApiClient
1111
/// </summary>
1212
/// <param name="cancellationToken"></param>
1313
/// <returns></returns>
14-
public Task<OneOf<Success<IReadOnlyCollection<ResponseDeviceWithShockers>>, UnauthenticatedError>> GetOwnShockers(CancellationToken cancellationToken = default);
14+
public Task<OneOf<Success<IReadOnlyCollection<ResponseDeviceWithShockers>>, UnauthenticatedError>> GetOwnShockers(
15+
CancellationToken cancellationToken = default);
1516

1617
/// <summary>
1718
/// Get the gateway a device is connected to
1819
/// </summary>
1920
/// <param name="deviceId"></param>
2021
/// <param name="cancellationToken"></param>
2122
/// <returns></returns>
22-
public Task<OneOf<Success<LcgResponse>, NotFound, DeviceOffline, DeviceNotConnectedToGateway, UnauthenticatedError>> GetDeviceGateway(Guid deviceId, CancellationToken cancellationToken = default);
23+
public Task<OneOf<Success<LcgResponse>, NotFound, DeviceOffline, DeviceNotConnectedToGateway, UnauthenticatedError>>
24+
GetDeviceGateway(Guid deviceId, CancellationToken cancellationToken = default);
25+
26+
/// <summary>
27+
/// Gets the root for the API, this has some useful information and can be used to check if the API is reachable
28+
/// </summary>
29+
/// <param name="cancellationToken"></param>
30+
/// <returns></returns>
31+
public Task<RootResponse> GetRoot(CancellationToken cancellationToken = default);
32+
2333
}
2434

2535
public struct DeviceOffline;

SDK.CSharp/Models/RootResponse.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace OpenShock.SDK.CSharp.Models;
2+
3+
public sealed class RootResponse
4+
{
5+
public required string Version { get; set; }
6+
public required string Commit { get; set; }
7+
public required DateTimeOffset CurrentTime { get; set; }
8+
public required Uri FrontendUrl { get; set; }
9+
public required Uri ShortLinkUrl { get; set; }
10+
}

SDK.CSharp/OpenShockApiClient.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ await gatewayResponse.Content.ReadAsJsonAsync<ProblemDetails>(cancellationToken,
9292
};
9393
}
9494

95+
/// <inheritdoc />
96+
public async Task<RootResponse> GetRoot(CancellationToken cancellationToken = default)
97+
{
98+
using var rootResponse = await _httpClient.GetAsync(OpenShockEndpoints.V1.Root, cancellationToken);
99+
return await rootResponse.Content.ReadBaseResponseAsJsonAsync<RootResponse>(cancellationToken, JsonSerializerOptions);
100+
}
101+
95102
private string GetUserAgent()
96103
{
97104
var liveClientAssembly = GetType().Assembly;

SDK.CSharp/OpenShockEndpoints.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ public static class OpenShockEndpoints
55

66
public static class V1
77
{
8+
public const string Root = "1";
9+
810
public static class Shockers
911
{
1012
public const string OwnShockers = "1/shockers/own";

SDK.CSharp/SDK.CSharp.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<AssemblyName>OpenShock.SDK.CSharp</AssemblyName>
99
<RootNamespace>OpenShock.SDK.CSharp</RootNamespace>
1010
<Company>OpenShock</Company>
11-
<AssemblyVersion>0.0.19</AssemblyVersion>
12-
<Version>0.0.19</Version>
13-
<Title>SDK.DotNet</Title>
11+
<AssemblyVersion>0.0.20</AssemblyVersion>
12+
<Version>0.0.20</Version>
13+
<Title>OpenShock.SDK.DotNet</Title>
1414
<Authors>OpenShock</Authors>
1515
<Description>.NET / C# SDK for developing OpenShock applications. Used to interact with a OpenShock backend.</Description>
1616
<PackageProjectUrl>https://openshock.org</PackageProjectUrl>
@@ -21,7 +21,6 @@
2121
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
2222
<IncludeSymbols>true</IncludeSymbols>
2323
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
24-
<RepositoryType>git</RepositoryType>
2524
<PackageReadmeFile>README.md</PackageReadmeFile>
2625
<PackageId>OpenShock.SDK.CSharp</PackageId>
2726
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

0 commit comments

Comments
 (0)