diff --git a/Octokit.Reactive/Clients/ObservableNotificationsClient.cs b/Octokit.Reactive/Clients/ObservableNotificationsClient.cs new file mode 100644 index 00000000..40893408 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableNotificationsClient.cs @@ -0,0 +1,37 @@ +using System; +using Octokit.Reactive.Internal; + +namespace Octokit.Reactive.Clients +{ + public class ObservableNotificationsClient : IObservableNotificationsClient + { + readonly IConnection _connection; + + public ObservableNotificationsClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _connection = client.Connection; + } + + /// + /// Retrieves all of the s for the current user. + /// + /// Thrown if the client is not authenticated. + /// A of . + public IObservable GetAllForCurrent() + { + return _connection.GetAndFlattenAllPages(ApiUrls.Notifications()); + } + + /// + /// Retrieves all of the s for the current user specific to the specified repository. + /// + /// Thrown if the client is not authenticated. + /// A of . + public IObservable GetAllForRepository(string owner, string name) + { + return _connection.GetAndFlattenAllPages(ApiUrls.Notifications(owner, name)); + } + } +} diff --git a/Octokit.Reactive/IObservableNotificationsClient.cs b/Octokit.Reactive/IObservableNotificationsClient.cs new file mode 100644 index 00000000..5b89d5ba --- /dev/null +++ b/Octokit.Reactive/IObservableNotificationsClient.cs @@ -0,0 +1,24 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +namespace Octokit.Reactive +{ + public interface IObservableNotificationsClient + { + /// + /// Retrieves all of the s for the current user. + /// + /// Thrown if the client is not authenticated. + /// A of . + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + IObservable GetAllForCurrent(); + + /// + /// Retrieves all of the s for the current user specific to the specified repository. + /// + /// Thrown if the client is not authenticated. + /// A of . + IObservable GetAllForRepository(string owner, string name); + + } +} diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index a097c449..455bee46 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -1,4 +1,4 @@ -using Octokit.Internal; +using Octokit.Reactive.Clients; namespace Octokit.Reactive { @@ -13,6 +13,7 @@ namespace Octokit.Reactive _gitHubClient = gitHubClient; Authorization = new ObservableAuthorizationsClient(gitHubClient); Miscellaneous = new ObservableMiscellaneousClient(gitHubClient.Miscellaneous); + Notification = new ObservableNotificationsClient(gitHubClient); Organization = new ObservableOrganizationsClient(gitHubClient); Repository = new ObservableRepositoriesClient(gitHubClient); SshKey = new ObservableSshKeysClient(gitHubClient); @@ -27,6 +28,7 @@ namespace Octokit.Reactive public IObservableAuthorizationsClient Authorization { get; private set; } public IObservableMiscellaneousClient Miscellaneous { get; private set; } + public IObservableNotificationsClient Notification { get; private set; } public IObservableOrganizationsClient Organization { get; private set; } public IObservableRepositoriesClient Repository { get; private set; } public IObservableReleasesClient Release { get; private set; } diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 3efb8cd4..8a5f6aad 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -85,6 +85,7 @@ Properties\SolutionInfo.cs + @@ -92,6 +93,7 @@ + diff --git a/Octokit.Tests/Clients/NotificationsClientTests.cs b/Octokit.Tests/Clients/NotificationsClientTests.cs new file mode 100644 index 00000000..36ab0949 --- /dev/null +++ b/Octokit.Tests/Clients/NotificationsClientTests.cs @@ -0,0 +1,39 @@ +using System; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class NotificationsClientTests + { + public class TheGetAllForCurrentMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var endpoint = new Uri("/notifications", UriKind.Relative); + var connection = Substitute.For(); + var client = new NotificationsClient(connection); + + client.GetAllForCurrent(); + + connection.Received().GetAll(endpoint); + } + } + + public class TheGetAllForRepository + { + [Fact] + public void RequestsCorrectUrl() + { + var endpoint = new Uri("/repos/banana/split/notifications", UriKind.Relative); + var connection = Substitute.For(); + var client = new NotificationsClient(connection); + + client.GetAllForRepository("banana", "split"); + + connection.Received().GetAll(endpoint); + } + } + } +} diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index e5f5608c..28cb43df 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -60,6 +60,7 @@ + diff --git a/Octokit.Tests/OctokitRT.Tests.csproj b/Octokit.Tests/OctokitRT.Tests.csproj index e084bcc3..911f87ba 100644 --- a/Octokit.Tests/OctokitRT.Tests.csproj +++ b/Octokit.Tests/OctokitRT.Tests.csproj @@ -52,6 +52,7 @@ + diff --git a/Octokit/Clients/NotificationsClient.cs b/Octokit/Clients/NotificationsClient.cs index 15682f24..2ff0eab3 100644 --- a/Octokit/Clients/NotificationsClient.cs +++ b/Octokit/Clients/NotificationsClient.cs @@ -10,9 +10,24 @@ namespace Octokit { } - public async Task> ListNotifications() + /// + /// Retrieves all of the s for the current user. + /// + /// Thrown if the client is not authenticated. + /// A of . + public async Task> GetAllForCurrent() { - return await Client.GetAll(new Uri("/notifications", UriKind.Relative)); + return await Client.GetAll(ApiUrls.Notifications()); + } + + /// + /// Retrieves all of the s for the current user specific to the specified repository. + /// + /// Thrown if the client is not authenticated. + /// A of . + public async Task> GetAllForRepository(string owner, string name) + { + return await Client.GetAll(ApiUrls.Notifications(owner, name)); } } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 7866ca5f..623d254a 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -12,7 +12,7 @@ namespace Octokit static readonly Uri _currentUserSshKeys = new Uri("/user/keys", UriKind.Relative); static readonly Uri _currentUserEmailsEndpoint = new Uri("/user/emails", UriKind.Relative); static readonly Uri _currentUserAuthorizationsEndpoint = new Uri("/authorizations", UriKind.Relative); - + static readonly Uri _currentUserNotificationsEndpoint = new Uri("/notifications", UriKind.Relative); /// /// Returns the that returns all of the repositories for the currently logged in user in @@ -111,5 +111,24 @@ namespace Octokit { return _currentUserAuthorizationsEndpoint; } + + /// + /// Returns the that returns all of the notifications for the currently logged in user. + /// + /// + public static Uri Notifications() + { + return _currentUserNotificationsEndpoint; + } + + /// + /// Returns the that returns all of the notifications for the currently logged in user + /// specific to the repository. + /// + /// + public static Uri Notifications(string owner, string name) + { + return "/repos/{0}/{1}/notifications".FormatUri(owner, name); + } } } diff --git a/Octokit/INotificationsClient.cs b/Octokit/INotificationsClient.cs index d029f963..fe870b0c 100644 --- a/Octokit/INotificationsClient.cs +++ b/Octokit/INotificationsClient.cs @@ -1,10 +1,24 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; namespace Octokit { public interface INotificationsClient { - Task> ListNotifications(); + /// + /// Retrieves all of the s for the current user. + /// + /// Thrown if the client is not authenticated. + /// A of . + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + Task> GetAllForCurrent(); + + /// + /// Retrieves all of the s for the current user specific to the specified repository. + /// + /// Thrown if the client is not authenticated. + /// A of . + Task> GetAllForRepository(string owner, string name); } }