mirror of
https://github.com/Stone-Red-Software/StoneRed.NetificationApi.git
synced 2026-09-04 16:56:05 +02:00
Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d43ca410e | ||
|
|
07f8409e88 | ||
|
|
fa47277eeb | ||
|
|
198ae4bfe7 | ||
|
|
02c16d4bd8 | ||
|
|
28a320a41a | ||
|
|
0b365b4964 | ||
|
|
d4b9ed769d | ||
|
|
e6f7f88785 | ||
|
|
d2149081f6 | ||
|
|
48c8ba32ea |
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
> A .NET library for NotificationAPI
|
> A .NET library for NotificationAPI
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> An official NotifcationAPI .NET server SDK is now available at [notificationapi-com/notificationapi-dotnet-server-sdk](https://github.com/notificationapi-com/notificationapi-dotnet-server-sdk)\
|
||||||
|
> Client-side functionality is currently not available in the official library, this is why this repository will still be maintained.
|
||||||
|
|
||||||
This is an *unofficial* library for [NotificationAPI](https://www.notificationapi.com/) and attempts to replicate the functionality of the official [Server SDK](https://docs.notificationapi.com/reference/server) and [JS Client SDK](https://docs.notificationapi.com/reference/js-client) as closely as possible.\
|
This is an *unofficial* library for [NotificationAPI](https://www.notificationapi.com/) and attempts to replicate the functionality of the official [Server SDK](https://docs.notificationapi.com/reference/server) and [JS Client SDK](https://docs.notificationapi.com/reference/js-client) as closely as possible.\
|
||||||
(A prebuilt notification widget is not included in this library.)
|
(A prebuilt notification widget is not included in this library.)
|
||||||
|
|
||||||
|
|||||||
@@ -73,9 +73,9 @@ notificationApiClient.RequestNotifications(5);
|
|||||||
Console.WriteLine("Notifications requested");
|
Console.WriteLine("Notifications requested");
|
||||||
|
|
||||||
Console.WriteLine("Identify user");
|
Console.WriteLine("Identify user");
|
||||||
await notificationApiServer.Identify(new IdentifyUserData
|
await notificationApiServer.Identify(userId, new IdentifyUserData
|
||||||
{
|
{
|
||||||
UserId = userId
|
Email = "[email protected]"
|
||||||
});
|
});
|
||||||
Console.WriteLine("User identified");
|
Console.WriteLine("User identified");
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Text.Json.Serialization;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace StoneRed.NetificationApi.Server.IdentifyUser;
|
namespace StoneRed.NetificationApi.Server.IdentifyUser;
|
||||||
|
|
||||||
@@ -8,12 +7,6 @@ namespace StoneRed.NetificationApi.Server.IdentifyUser;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class IdentifyUserData
|
public class IdentifyUserData
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the user ID.
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore]
|
|
||||||
public required string UserId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the email address of the user.
|
/// Gets or sets the email address of the user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -34,21 +27,4 @@ public class IdentifyUserData
|
|||||||
/// Gets or sets the list of web push tokens for the user.
|
/// Gets or sets the list of web push tokens for the user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<NotificationWebPushToken>? WebPushTokens { get; set; }
|
public List<NotificationWebPushToken>? WebPushTokens { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="IdentifyUserData"/> class with the specified user ID.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="userId">The user ID.</param>
|
|
||||||
[SetsRequiredMembers]
|
|
||||||
public IdentifyUserData(string userId)
|
|
||||||
{
|
|
||||||
UserId = userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="IdentifyUserData"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public IdentifyUserData()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -76,31 +76,26 @@ public class NotificationApiServer
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Identifies a user.
|
/// Identifies a user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="userId">The ID of the user.</param>
|
||||||
/// <param name="identifyUserData">The data for identifying the user.</param>
|
/// <param name="identifyUserData">The data for identifying the user.</param>
|
||||||
/// <returns>The HTTP response message.</returns>
|
/// <returns>The HTTP response message.</returns>
|
||||||
public async Task<HttpResponseMessage> Identify(IdentifyUserData identifyUserData)
|
public async Task<HttpResponseMessage> Identify(string userId, IdentifyUserData identifyUserData)
|
||||||
{
|
{
|
||||||
string authToken;
|
string authToken;
|
||||||
|
|
||||||
if (secureMode)
|
if (secureMode)
|
||||||
{
|
{
|
||||||
string hashedUserId = UserIdHasher.Hash(identifyUserData.UserId, clientSecret);
|
string hashedUserId = UserIdHasher.Hash(userId, clientSecret);
|
||||||
authToken = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{clientId}:{identifyUserData.UserId}:{hashedUserId}"));
|
authToken = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{clientId}:{userId}:{hashedUserId}"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
authToken = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{clientId}:{identifyUserData.UserId}"));
|
authToken = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{clientId}:{userId}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
var requestData = new
|
HttpRequestMessage request = new(HttpMethod.Post, $"users/{userId}")
|
||||||
{
|
{
|
||||||
email = identifyUserData.Email,
|
Content = JsonContent.Create(identifyUserData, options: Configuration.JsonSerializerOptions),
|
||||||
number = identifyUserData.TelephoneNumber,
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpRequestMessage request = new(HttpMethod.Post, $"users/{identifyUserData.UserId}")
|
|
||||||
{
|
|
||||||
Content = JsonContent.Create(requestData, options: Configuration.JsonSerializerOptions),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
request.Headers.Add("Authorization", $"Basic {authToken}");
|
request.Headers.Add("Authorization", $"Basic {authToken}");
|
||||||
@@ -111,10 +106,11 @@ public class NotificationApiServer
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets user preferences.
|
/// Sets user preferences.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="userId">The ID of the user.</param>
|
||||||
/// <param name="setUserPreferencesData">The data for setting user preferences.</param>
|
/// <param name="setUserPreferencesData">The data for setting user preferences.</param>
|
||||||
/// <returns>The HTTP response message.</returns>
|
/// <returns>The HTTP response message.</returns>
|
||||||
public async Task<HttpResponseMessage> SetUserPreferences(SetUserPreferencesData setUserPreferencesData)
|
public async Task<HttpResponseMessage> SetUserPreferences(string userId, SetUserPreferencesData setUserPreferencesData)
|
||||||
{
|
{
|
||||||
return await httpClient.PostAsJsonAsync($"user_preferences/{setUserPreferencesData.UserId}", setUserPreferencesData, Configuration.JsonSerializerOptions);
|
return await httpClient.PostAsJsonAsync($"user_preferences/{userId}", setUserPreferencesData.Preferences, Configuration.JsonSerializerOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace StoneRed.NetificationApi.Server.SetUserPreferences;
|
namespace StoneRed.NetificationApi.Server.SetUserPreferences;
|
||||||
|
|
||||||
@@ -8,12 +7,6 @@ namespace StoneRed.NetificationApi.Server.SetUserPreferences;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SetUserPreferencesData
|
public class SetUserPreferencesData
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the user ID.
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore]
|
|
||||||
public required string UserId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the list of notification preferences.
|
/// Gets or sets the list of notification preferences.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -22,12 +15,10 @@ public class SetUserPreferencesData
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SetUserPreferencesData"/> class.
|
/// Initializes a new instance of the <see cref="SetUserPreferencesData"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">The user ID.</param>
|
|
||||||
/// <param name="preferences">The list of notification preferences.</param>
|
/// <param name="preferences">The list of notification preferences.</param>
|
||||||
[SetsRequiredMembers]
|
[SetsRequiredMembers]
|
||||||
public SetUserPreferencesData(string userId, List<NotificationPreference> preferences)
|
public SetUserPreferencesData(List<NotificationPreference> preferences)
|
||||||
{
|
{
|
||||||
UserId = userId;
|
|
||||||
Preferences = preferences;
|
Preferences = preferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,33 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
<Version>1.0.3.0</Version>
|
<Version>1.0.4.20240314</Version>
|
||||||
<RepositoryUrl>https://github.com/Stone-Red-Software/StoneRed.NetificationApi</RepositoryUrl>
|
<RepositoryUrl>https://github.com/Stone-Red-Software/StoneRed.NetificationApi</RepositoryUrl>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
<Description>A .NET library for NotificationAPI</Description>
|
<Description>A .NET library for NotificationAPI</Description>
|
||||||
<PackageProjectUrl>https://github.com/Stone-Red-Software/StoneRed.NetificationApi</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/Stone-Red-Software/StoneRed.NetificationApi</PackageProjectUrl>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<PropertyGroup>
|
||||||
<None Include="..\..\README.md">
|
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
|
||||||
<Pack>True</Pack>
|
<Deterministic>False</Deterministic>
|
||||||
<PackagePath>\</PackagePath>
|
</PropertyGroup>
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Websocket.Client" Version="5.1.1" />
|
<None Include="..\..\README.md">
|
||||||
</ItemGroup>
|
<Pack>True</Pack>
|
||||||
|
<PackagePath>\</PackagePath>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Websocket.Client" Version="5.1.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user