using System.Collections.Generic; using System.Threading.Tasks; namespace Octokit { /// /// A client for GitHub's Activity Notifications API. /// /// /// See the Activity Notifications API documentation for more information. /// public class NotificationsClient : ApiClient, INotificationsClient { /// /// Instantiates a new GitHub Activity Notifications API client. /// /// An API connection public NotificationsClient(IApiConnection apiConnection) : base(apiConnection) { } /// /// Retrieves all of the s for the current user. /// /// Thrown if the client is not authenticated. public Task> 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 Task> GetAllForCurrent(ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); return ApiConnection.GetAll(ApiUrls.Notifications(), 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 Task> GetAllForCurrent(NotificationsRequest request) { Ensure.ArgumentNotNull(request, "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 Task> GetAllForCurrent(NotificationsRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return ApiConnection.GetAll(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. /// Thrown if the client is not authenticated. public Task> GetAllForRepository(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "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 Task> 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 Task> GetAllForRepository(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); return ApiConnection.GetAll(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 Task> GetAllForRepository(long repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); return ApiConnection.GetAll(ApiUrls.Notifications(repositoryId), 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 Task> GetAllForRepository(string owner, string name, NotificationsRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "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 Task> GetAllForRepository(long repositoryId, NotificationsRequest request) { Ensure.ArgumentNotNull(request, "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 Task> GetAllForRepository(string owner, string name, NotificationsRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return ApiConnection.GetAll(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 Task> GetAllForRepository(long repositoryId, NotificationsRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return ApiConnection.GetAll(ApiUrls.Notifications(repositoryId), request.ToParametersDictionary(), options); } /// /// Marks all notifications as read. /// /// http://developer.github.com/v3/activity/notifications/#mark-as-read public Task MarkAsRead() { return ApiConnection.Put(ApiUrls.Notifications(), new object()); } /// /// Marks all notifications as read. /// /// The parameter which specifies which notifications to mark. /// http://developer.github.com/v3/activity/notifications/#mark-as-read public Task MarkAsRead(MarkAsReadRequest markAsReadRequest) { Ensure.ArgumentNotNull(markAsReadRequest, "markAsReadRequest"); return ApiConnection.Put(ApiUrls.Notifications(), markAsReadRequest); } /// /// 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 Task MarkAsReadForRepository(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return ApiConnection.Put(ApiUrls.Notifications(owner, name), new object()); } /// /// 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 Task MarkAsReadForRepository(long repositoryId) { return ApiConnection.Put(ApiUrls.Notifications(repositoryId), new object()); } /// /// 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 Task MarkAsReadForRepository(string owner, string name, MarkAsReadRequest markAsReadRequest) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(markAsReadRequest, "markAsReadRequest"); return ApiConnection.Put(ApiUrls.Notifications(owner, name), markAsReadRequest); } /// /// 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 Task MarkAsReadForRepository(long repositoryId, MarkAsReadRequest markAsReadRequest) { Ensure.ArgumentNotNull(markAsReadRequest, "markAsReadRequest"); return ApiConnection.Put(ApiUrls.Notifications(repositoryId), markAsReadRequest); } /// /// Retrives a single by Id. /// /// The Id of the notification to retrieve. /// http://developer.github.com/v3/activity/notifications/#view-a-single-thread public Task Get(int id) { return ApiConnection.Get(ApiUrls.Notification(id)); } /// /// Marks a single notification as read. /// /// The id of the notification. /// http://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read public Task MarkAsRead(int id) { return ApiConnection.Patch(ApiUrls.Notification(id)); } /// /// 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 Task GetThreadSubscription(int id) { return ApiConnection.Get(ApiUrls.NotificationSubscription(id)); } /// /// 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 Task SetThreadSubscription(int id, NewThreadSubscription threadSubscription) { Ensure.ArgumentNotNull(threadSubscription, "threadSubscription"); return ApiConnection.Put(ApiUrls.NotificationSubscription(id), threadSubscription); } /// /// 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 Task DeleteThreadSubscription(int id) { return ApiConnection.Delete(ApiUrls.NotificationSubscription(id)); } } }