Innovenergy_trunk/csharp/Lib/Victron/VictronVRM/Requests.cs

61 lines
2.0 KiB
C#

using Flurl;
using Flurl.Http;
namespace InnovEnergy.Lib.Victron.VictronVRM;
public static class Requests
{
private const String ApiRoot = "https://vrmapi.victronenergy.com/v2/";
public static FlurlRequest LoginRequest { get; } = new FlurlRequest(ApiRoot.AppendPathSegments("auth", "login"));
public static IFlurlRequest LogoutRequest(this VrmAccount account)
{
return ApiRoot
.AppendPathSegments("auth", "logout")
.WithHeader("X-Authorization", account.Auth);
}
public static IFlurlRequest DetailsRequest(this VrmAccount account, UInt64 installationId, Int32 nDetails = 1000)
{
return InstallationRequest(account, installationId)
.AppendPathSegment("diagnostics")
.SetQueryParams(new { count = nDetails });
}
public static IFlurlRequest InstallationRequest(this VrmAccount account, UInt64 installationId)
{
return ApiRoot
.AppendPathSegment("installations")
.AppendPathSegment(installationId)
.WithHeader("X-Authorization", account.Auth);
}
public static IFlurlRequest AllInstallationsRequest(this VrmAccount account)
{
return ApiRoot
.AppendPathSegment("users")
.AppendPathSegment(account.UserId)
.AppendPathSegment("installations")
.WithHeader("X-Authorization", account.Auth);
}
public static IFlurlRequest TagsRequest(this VrmAccount account, UInt64 installationId)
{
return InstallationRequest(account, installationId)
.AppendPathSegment("tags");
}
public static IFlurlRequest SettingsRequest(this VrmAccount account, UInt64 installationId)
{
return InstallationRequest(account, installationId)
.AppendPathSegment("settings");
}
public static IFlurlRequest DevicesRequest(this VrmAccount account, UInt64 installationId)
{
return InstallationRequest(account, installationId)
.AppendPathSegment("system-overview");
}
}