Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add base for notifications endpoint #80

Merged
merged 2 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Modrinth.Net/Endpoints/Notifications/INotificationsEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Modrinth.Exceptions;
using Modrinth.Models;

namespace Modrinth.Endpoints.Notifications;

/// <summary>
/// Notifications endpoints
/// </summary>
public interface INotificationsEndpoint
{
/// <summary>
/// Gets all notifications of a user by their username or ID
/// Requires authentication
/// </summary>
/// <param name="usernameOrId"> The username or ID of the user to retrieve notifications from </param>
/// <returns> An array of notifications </returns>
/// <exception cref="ModrinthApiException"> Thrown when the API returns an error or the request fails </exception>
Task<Notification[]> GetNotificationsAsync(string usernameOrId);
}
23 changes: 23 additions & 0 deletions src/Modrinth.Net/Endpoints/Notifications/NotificationsEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Modrinth.Http;
using Modrinth.Models;

namespace Modrinth.Endpoints.Notifications;

/// <inheritdoc cref="Modrinth.Endpoints.Notifications.INotificationsEndpoint" />
public class NotificationsEndpoint : Endpoint, INotificationsEndpoint
{
/// <inheritdoc />
public NotificationsEndpoint(IRequester requester) : base(requester)
{
}

/// <inheritdoc />
public async Task<Notification[]> GetNotificationsAsync(string usernameOrId)
{
var reqMsg = new HttpRequestMessage();
reqMsg.Method = HttpMethod.Get;
reqMsg.RequestUri = new Uri("user" + '/' + usernameOrId + '/' + "notifications", UriKind.Relative);

return await Requester.GetJsonAsync<Notification[]>(reqMsg).ConfigureAwait(false);
}
}
10 changes: 0 additions & 10 deletions src/Modrinth.Net/Endpoints/User/IUserEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Modrinth.Exceptions;
using Modrinth.Models;

namespace Modrinth.Endpoints.User;

Expand Down Expand Up @@ -40,15 +39,6 @@ public interface IUserEndpoint
/// <exception cref="ModrinthApiException"> Thrown when the API returns an error or the request fails </exception>
Task<Models.User> GetCurrentAsync();

/// <summary>
/// Gets all notifications of a user by their username or ID
/// Requires authentication
/// </summary>
/// <param name="usernameOrId"> The username or ID of the user to retrieve notifications from </param>
/// <returns> An array of notifications </returns>
/// <exception cref="ModrinthApiException"> Thrown when the API returns an error or the request fails </exception>
Task<Notification[]> GetNotificationsAsync(string usernameOrId);

/// <summary>
/// Gets all followed projects of a user by their username or ID
/// Requires authentication
Expand Down
12 changes: 0 additions & 12 deletions src/Modrinth.Net/Endpoints/User/UserEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Modrinth.Extensions;
using Modrinth.Http;
using Modrinth.Models;
using File = System.IO.File;

namespace Modrinth.Endpoints.User;

Expand Down Expand Up @@ -62,16 +60,6 @@ public UserEndpoint(IRequester requester) : base(requester)
return await Requester.GetJsonAsync<Models.User>(reqMsg).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<Notification[]> GetNotificationsAsync(string usernameOrId)
{
var reqMsg = new HttpRequestMessage();
reqMsg.Method = HttpMethod.Get;
reqMsg.RequestUri = new Uri(UserPathSegment + '/' + usernameOrId + '/' + "notifications", UriKind.Relative);

return await Requester.GetJsonAsync<Notification[]>(reqMsg).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<Models.Project[]> GetFollowedProjectsAsync(string usernameOrId)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Modrinth.Net/IModrinthClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Modrinth.Endpoints.Miscellaneous;
using Modrinth.Endpoints.Notifications;
using Modrinth.Endpoints.Project;
using Modrinth.Endpoints.Tag;
using Modrinth.Endpoints.Team;
Expand Down Expand Up @@ -38,4 +39,7 @@ public interface IModrinthClient : IDisposable

/// <inheritdoc cref="IMiscellaneousEndpoint" />
IMiscellaneousEndpoint Miscellaneous { get; }

/// <inheritdoc cref="INotificationsEndpoint" />
INotificationsEndpoint Notification { get; }
}
1 change: 1 addition & 0 deletions src/Modrinth.Net/Modrinth.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
</None>
</ItemGroup>


</Project>
5 changes: 5 additions & 0 deletions src/Modrinth.Net/ModrinthClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Modrinth.Endpoints.Miscellaneous;
using Modrinth.Endpoints.Notifications;
using Modrinth.Endpoints.Project;
using Modrinth.Endpoints.Tag;
using Modrinth.Endpoints.Team;
Expand Down Expand Up @@ -89,6 +90,7 @@ public ModrinthClient(ModrinthClientConfig config, HttpClient? httpClient = null
Version = new VersionEndpoint(_requester);
VersionFile = new VersionFileEndpoint(_requester);
Miscellaneous = new MiscellaneousEndpoint(_requester);
Notification = new NotificationsEndpoint(_requester);
}

/// <inheritdoc />
Expand Down Expand Up @@ -126,5 +128,8 @@ public void Dispose()
/// <inheritdoc />
public IMiscellaneousEndpoint Miscellaneous { get; }

/// <inheritdoc />
public INotificationsEndpoint Notification { get; }

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Modrinth.Net.Test.ModrinthApiTests;

[TestFixture]
public class NotificationsEndpointTests : EndpointTests
{
[Test]
public async Task TestGetNotifications()
{
var current = await Client.User.GetCurrentAsync();

var notifications = await Client.Notification.GetNotificationsAsync(current.Id);

Assert.That(notifications, Is.Not.Null);
}
}
10 changes: 0 additions & 10 deletions test/Modrinth.Net.Test/ModrinthApiTests/UserEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ public async Task TestGetCurrentUser()
Assert.That(user, Is.Not.Null);
}

[Test]
public async Task TestGetNotifications()
{
var current = await Client.User.GetCurrentAsync();

var notifications = await Client.User.GetNotificationsAsync(current.Id);

Assert.That(notifications, Is.Not.Null);
}

[Test]
public async Task TestGetFollowedProjects()
{
Expand Down