using System; using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { /// /// A client for GitHub's Activity Notifications API. /// /// /// See the Activity Notifications API documentation for more information. /// public class ObservableNotificationsClient : IObservableNotificationsClient { readonly IConnection _connection; readonly INotificationsClient _notificationsClient; public ObservableNotificationsClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); _connection = client.Connection; _notificationsClient = client.Activity.Notifications; } /// /// Retrieves all of the s for the current user. /// /// Thrown if the client is not authenticated. public IObservable GetAllForCurrent() { return GetAllForCurrent(ApiOptions.None); } /// /// Retrieves all of the s for the current user. /// /// Options for changing the API response /// Thrown if the client is not authenticated. public IObservable GetAllForCurrent(ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Notifications(), options); } /// /// Retrieves all of the s for the current user specific to the specified repository. /// /// The owner of the repository. /// The name of the repository. /// Thrown if the client is not authenticated. public IObservable GetAllForRepository(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return GetAllForRepository(owner, name, ApiOptions.None); } /// /// Retrieves all of the s for the current user specific to the specified repository. /// /// The Id of the repository. /// Thrown if the client is not authenticated. public IObservable GetAllForRepository(long repositoryId) { return GetAllForRepository(repositoryId, ApiOptions.None); } /// /// Retrieves all of the s for the current user specific to the specified repository. /// /// The owner of the repository. /// The name of the repository. /// Options for changing the API response /// Thrown if the client is not authenticated. public IObservable GetAllForRepository(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Notifications(owner, name), options); } /// /// Retrieves all of the s for the current user specific to the specified repository. /// /// The Id of the repository. /// Options for changing the API response /// Thrown if the client is not authenticated. public IObservable GetAllForRepository(long repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Notifications(repositoryId), options); } /// /// Retrieves all of the s for the current user. /// /// Specifies the parameters to filter notifications by /// Thrown if the client is not authenticated. public IObservable GetAllForCurrent(NotificationsRequest request) { Ensure.ArgumentNotNull(request, nameof(request)); return GetAllForCurrent(request, ApiOptions.None); } /// /// Retrieves all of the s for the current user. /// /// Specifies the parameters to filter notifications by /// Options for changing the API response /// Thrown if the client is not authenticated. public IObservable GetAllForCurrent(NotificationsRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Notifications(), request.ToParametersDictionary(), options); } /// /// Retrieves all of the s for the current user specific to the specified repository. /// /// The owner of the repository. /// The name of the repository. /// Specifies the parameters to filter notifications by /// Thrown if the client is not authenticated. public IObservable GetAllForRepository(string owner, string name, NotificationsRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(request, nameof(request)); return GetAllForRepository(owner, name, request, ApiOptions.None); } /// /// Retrieves all of the s for the current user specific to the specified repository. /// /// The Id of the repository. /// Specifies the parameters to filter notifications by /// Thrown if the client is not authenticated. public IObservable GetAllForRepository(long repositoryId, NotificationsRequest request) { Ensure.ArgumentNotNull(request, nameof(request)); return GetAllForRepository(repositoryId, request, ApiOptions.None); } /// /// Retrieves all of the s for the current user specific to the specified repository. /// /// The owner of the repository. /// The name of the repository. /// Specifies the parameters to filter notifications by /// Options for changing the API response /// Thrown if the client is not authenticated. public IObservable GetAllForRepository(string owner, string name, NotificationsRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Notifications(owner, name), request.ToParametersDictionary(), options); } /// /// Retrieves all of the s for the current user specific to the specified repository. /// /// The Id of the repository. /// Specifies the parameters to filter notifications by /// Options for changing the API response /// Thrown if the client is not authenticated. public IObservable GetAllForRepository(long repositoryId, NotificationsRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Notifications(repositoryId), request.ToParametersDictionary(), options); } /// /// Marks all notifications as read. /// /// http://developer.github.com/v3/activity/notifications/#mark-as-read public IObservable MarkAsRead() { return _notificationsClient.MarkAsRead().ToObservable(); } /// /// Marks all notifications as read. /// /// The parameter which specifies which notifications to mark. /// http://developer.github.com/v3/activity/notifications/#mark-as-read public IObservable MarkAsRead(MarkAsReadRequest markAsReadRequest) { Ensure.ArgumentNotNull(markAsReadRequest, nameof(markAsReadRequest)); return _notificationsClient.MarkAsRead(markAsReadRequest).ToObservable(); } /// /// Marks the notifications for a given repository as read. /// /// The owner of the repository /// The name of the repository /// http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository public IObservable MarkAsReadForRepository(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _notificationsClient.MarkAsReadForRepository(owner, name).ToObservable(); } /// /// Marks the notifications for a given repository as read. /// /// The Id of the repository /// http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository public IObservable MarkAsReadForRepository(long repositoryId) { return _notificationsClient.MarkAsReadForRepository(repositoryId).ToObservable(); } /// /// Marks the notifications for a given repository as read. /// /// The owner of the repository /// The name of the repository /// The parameter which specifies which notifications to mark. /// http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository public IObservable MarkAsReadForRepository(string owner, string name, MarkAsReadRequest markAsReadRequest) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(markAsReadRequest, nameof(markAsReadRequest)); return _notificationsClient.MarkAsReadForRepository(owner, name, markAsReadRequest).ToObservable(); } /// /// Marks the notifications for a given repository as read. /// /// The Id of the repository /// The parameter which specifies which notifications to mark. /// http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository public IObservable MarkAsReadForRepository(long repositoryId, MarkAsReadRequest markAsReadRequest) { Ensure.ArgumentNotNull(markAsReadRequest, nameof(markAsReadRequest)); return _notificationsClient.MarkAsReadForRepository(repositoryId, markAsReadRequest).ToObservable(); } /// /// Retrives a single by Id. /// /// The Id of the notification to retrieve. /// http://developer.github.com/v3/activity/notifications/#view-a-single-thread public IObservable Get(int notificationId) { return _notificationsClient.Get(notificationId).ToObservable(); } /// /// Marks a single notification as read. /// /// The id of the notification. /// http://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read public IObservable MarkAsRead(int notificationId) { return _notificationsClient.MarkAsRead(notificationId).ToObservable(); } /// /// Retrives a for the provided thread id. /// /// The Id of the thread to retrieve subscription status. /// http://developer.github.com/v3/activity/notifications/#get-a-thread-subscription public IObservable GetThreadSubscription(int threadId) { return _notificationsClient.GetThreadSubscription(threadId).ToObservable(); } /// /// Sets the authenticated user's subscription settings for a given thread. /// /// The Id of the thread to update. /// The subscription parameters to set. /// http://developer.github.com/v3/activity/notifications/#set-a-thread-subscription public IObservable SetThreadSubscription(int threadId, NewThreadSubscription threadSubscription) { Ensure.ArgumentNotNull(threadSubscription, nameof(threadSubscription)); return _notificationsClient.SetThreadSubscription(threadId, threadSubscription).ToObservable(); } /// /// Deletes the authenticated user's subscription to a given thread. /// /// The Id of the thread to delete subscription from. /// http://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription public IObservable DeleteThreadSubscription(int threadId) { return _notificationsClient.DeleteThreadSubscription(threadId).ToObservable(); } } }