mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-05 23:06:10 +00:00
* bugfix - PUT should have a payload for Mark as Read (#1579) * bugfix - PUT should have a payload for Mark as Read * also fix the Observable client test * add integration tests for MarkRead methods * Fixup MarkReadForRepository methods to specify a body in the PUT request * Fix unit tests for regular and observable client * helps if the new files are included in the test project :) * Cloning ApiInfo object should work when some fields are null (#1580) * Adjust ApiInfo.Clone() to work even if some elements (eg ETag) are null * Remove c# 6 language feature and do it the old school way * Add a test for cloning ApiInfo when some fields are null * The 3 lists can never be null anyway so remove some un-needed statements * Add test for null RateLimit * Remove Rx-Main dependency from samples This resolves #1592 - LINQPad doesn't understand how to restore this unlisted package and it's not actually needed in the samples. * Adding RemovedFromProject and other missing EventInfoState types. (#1591) * Adding missing review types to event info. * Fixing whitespace. * Reword `BaseRefChanged` comment * Adding missing event types. * Change response models 'Url' properties from `Uri` to `string` (#1585) * Add convention test to ensure 'Url' properties are of type string Closes #1582 * Change 'Url' properties from Uri to string Global Find/Replace FTW! * fix compilation errors in the integration tests project * Extend 'Url' properties type check to request models * Stick to convention tests naming convention * Remove unused using directives in models Changing from `Uri` to `string` means the `using System;` directive was not needed anymore in some files * Update exception message wording * empty commit to trigger a new build - hopefully Travis passes * add convention test to ensure request models have Uri 'Url' properties * make request models 'Url' properties Uri fix typo in convention test name * revert some request models 'Url' properties as `string` see https://github.com/octokit/octokit.net/pull/1585#issuecomment-297186728 * Change test so that all model types must have 'Url' properties of type string - Filter test input to only get types which have 'Url' properties - Merge response and request model types tests into one - Unparameterize the exception since we only check for the string type now * Fix string.Format tokens If this PR doesn't get rebased, it'll be my wall of shame FOREVER! * and then it's even more embarrassing when the commit message says rebased but you really meant squashed * Remove exclusion of `Release` from request models
312 lines
16 KiB
C#
312 lines
16 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Octokit
|
|
{
|
|
/// <summary>
|
|
/// A client for GitHub's Activity Notifications API.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/activity/notifications/">Activity Notifications API documentation</a> for more information.
|
|
/// </remarks>
|
|
public class NotificationsClient : ApiClient, INotificationsClient
|
|
{
|
|
/// <summary>
|
|
/// Instantiates a new GitHub Activity Notifications API client.
|
|
/// </summary>
|
|
/// <param name="apiConnection">An API connection</param>
|
|
public NotificationsClient(IApiConnection apiConnection) : base(apiConnection)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all of the <see cref="Notification"/>s for the current user.
|
|
/// </summary>
|
|
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
|
public Task<IReadOnlyList<Notification>> GetAllForCurrent()
|
|
{
|
|
return GetAllForCurrent(ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all of the <see cref="Notification"/>s for the current user.
|
|
/// </summary>
|
|
/// <param name="options">Options for changing the API response</param>
|
|
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
|
public Task<IReadOnlyList<Notification>> GetAllForCurrent(ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNull(options, "options");
|
|
|
|
return ApiConnection.GetAll<Notification>(ApiUrls.Notifications(), options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all of the <see cref="Notification"/>s for the current user.
|
|
/// </summary>
|
|
/// <param name="request">Specifies the parameters to filter notifications by</param>
|
|
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
|
public Task<IReadOnlyList<Notification>> GetAllForCurrent(NotificationsRequest request)
|
|
{
|
|
Ensure.ArgumentNotNull(request, "request");
|
|
|
|
return GetAllForCurrent(request, ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all of the <see cref="Notification"/>s for the current user.
|
|
/// </summary>
|
|
/// <param name="request">Specifies the parameters to filter notifications by</param>
|
|
/// <param name="options">Options for changing the API response</param>
|
|
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
|
public Task<IReadOnlyList<Notification>> GetAllForCurrent(NotificationsRequest request, ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNull(request, "request");
|
|
Ensure.ArgumentNotNull(options, "options");
|
|
|
|
return ApiConnection.GetAll<Notification>(ApiUrls.Notifications(), request.ToParametersDictionary(), options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository.</param>
|
|
/// <param name="name">The name of the repository.</param>
|
|
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
|
public Task<IReadOnlyList<Notification>> GetAllForRepository(string owner, string name)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
|
|
return GetAllForRepository(owner, name, ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
|
|
/// </summary>
|
|
/// <param name="repositoryId">The Id of the repository.</param>
|
|
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
|
public Task<IReadOnlyList<Notification>> GetAllForRepository(long repositoryId)
|
|
{
|
|
return GetAllForRepository(repositoryId, ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository.</param>
|
|
/// <param name="name">The name of the repository.</param>
|
|
/// <param name="options">Options for changing the API response</param>
|
|
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
|
public Task<IReadOnlyList<Notification>> GetAllForRepository(string owner, string name, ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
Ensure.ArgumentNotNull(options, "options");
|
|
|
|
return ApiConnection.GetAll<Notification>(ApiUrls.Notifications(owner, name), options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
|
|
/// </summary>
|
|
/// <param name="repositoryId">The Id of the repository.</param>
|
|
/// <param name="options">Options for changing the API response</param>
|
|
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
|
public Task<IReadOnlyList<Notification>> GetAllForRepository(long repositoryId, ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNull(options, "options");
|
|
|
|
return ApiConnection.GetAll<Notification>(ApiUrls.Notifications(repositoryId), options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository.</param>
|
|
/// <param name="name">The name of the repository.</param>
|
|
/// <param name="request">Specifies the parameters to filter notifications by</param>
|
|
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
|
public Task<IReadOnlyList<Notification>> 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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
|
|
/// </summary>
|
|
/// <param name="repositoryId">The Id of the repository.</param>
|
|
/// <param name="request">Specifies the parameters to filter notifications by</param>
|
|
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
|
public Task<IReadOnlyList<Notification>> GetAllForRepository(long repositoryId, NotificationsRequest request)
|
|
{
|
|
Ensure.ArgumentNotNull(request, "request");
|
|
|
|
return GetAllForRepository(repositoryId, request, ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository.</param>
|
|
/// <param name="name">The name of the repository.</param>
|
|
/// <param name="request">Specifies the parameters to filter notifications by</param>
|
|
/// <param name="options">Options for changing the API response</param>
|
|
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
|
public Task<IReadOnlyList<Notification>> 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<Notification>(ApiUrls.Notifications(owner, name), request.ToParametersDictionary(), options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
|
|
/// </summary>
|
|
/// <param name="repositoryId">The Id of the repository.</param>
|
|
/// <param name="request">Specifies the parameters to filter notifications by</param>
|
|
/// <param name="options">Options for changing the API response</param>
|
|
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
|
public Task<IReadOnlyList<Notification>> GetAllForRepository(long repositoryId, NotificationsRequest request, ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNull(request, "request");
|
|
Ensure.ArgumentNotNull(options, "options");
|
|
|
|
return ApiConnection.GetAll<Notification>(ApiUrls.Notifications(repositoryId), request.ToParametersDictionary(), options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks all notifications as read.
|
|
/// </summary>
|
|
/// <remarks>http://developer.github.com/v3/activity/notifications/#mark-as-read</remarks>
|
|
public Task MarkAsRead()
|
|
{
|
|
return ApiConnection.Put<object>(ApiUrls.Notifications(), new object());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks all notifications as read.
|
|
/// </summary>
|
|
/// <param name="markAsReadRequest">The <see cref="MarkAsReadRequest"/> parameter which specifies which notifications to mark.</param>
|
|
/// <remarks>http://developer.github.com/v3/activity/notifications/#mark-as-read</remarks>
|
|
public Task MarkAsRead(MarkAsReadRequest markAsReadRequest)
|
|
{
|
|
Ensure.ArgumentNotNull(markAsReadRequest, "markAsReadRequest");
|
|
|
|
return ApiConnection.Put<object>(ApiUrls.Notifications(), markAsReadRequest);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks the notifications for a given repository as read.
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <remarks>http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository</remarks>
|
|
public Task MarkAsReadForRepository(string owner, string name)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
|
|
return ApiConnection.Put<object>(ApiUrls.Notifications(owner, name), new object());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks the notifications for a given repository as read.
|
|
/// </summary>
|
|
/// <param name="repositoryId">The Id of the repository</param>
|
|
/// <remarks>http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository</remarks>
|
|
public Task MarkAsReadForRepository(long repositoryId)
|
|
{
|
|
return ApiConnection.Put<object>(ApiUrls.Notifications(repositoryId), new object());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks the notifications for a given repository as read.
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <param name="markAsReadRequest">The <see cref="MarkAsReadRequest"/> parameter which specifies which notifications to mark.</param>
|
|
/// <remarks>http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository</remarks>
|
|
public Task MarkAsReadForRepository(string owner, string name, MarkAsReadRequest markAsReadRequest)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
Ensure.ArgumentNotNull(markAsReadRequest, "markAsReadRequest");
|
|
|
|
return ApiConnection.Put<object>(ApiUrls.Notifications(owner, name), markAsReadRequest);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks the notifications for a given repository as read.
|
|
/// </summary>
|
|
/// <param name="repositoryId">The Id of the repository</param>
|
|
/// <param name="markAsReadRequest">The <see cref="MarkAsReadRequest"/> parameter which specifies which notifications to mark.</param>
|
|
/// <remarks>http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository</remarks>
|
|
public Task MarkAsReadForRepository(long repositoryId, MarkAsReadRequest markAsReadRequest)
|
|
{
|
|
Ensure.ArgumentNotNull(markAsReadRequest, "markAsReadRequest");
|
|
|
|
return ApiConnection.Put<object>(ApiUrls.Notifications(repositoryId), markAsReadRequest);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrives a single <see cref="Notification"/> by Id.
|
|
/// </summary>
|
|
/// <param name="id">The Id of the notification to retrieve.</param>
|
|
/// <remarks>http://developer.github.com/v3/activity/notifications/#view-a-single-thread</remarks>
|
|
public Task<Notification> Get(int id)
|
|
{
|
|
return ApiConnection.Get<Notification>(ApiUrls.Notification(id));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks a single notification as read.
|
|
/// </summary>
|
|
/// <param name="id">The id of the notification.</param>
|
|
/// <remarks>http://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read</remarks>
|
|
public Task MarkAsRead(int id)
|
|
{
|
|
return ApiConnection.Patch(ApiUrls.Notification(id));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrives a <see cref="ThreadSubscription"/> for the provided thread id.
|
|
/// </summary>
|
|
/// <param name="id">The Id of the thread to retrieve subscription status.</param>
|
|
/// <remarks>http://developer.github.com/v3/activity/notifications/#get-a-thread-subscription</remarks>
|
|
public Task<ThreadSubscription> GetThreadSubscription(int id)
|
|
{
|
|
return ApiConnection.Get<ThreadSubscription>(ApiUrls.NotificationSubscription(id));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the authenticated user's subscription settings for a given thread.
|
|
/// </summary>
|
|
/// <param name="id">The Id of the thread to update.</param>
|
|
/// <param name="threadSubscription">The subscription parameters to set.</param>
|
|
/// <remarks>http://developer.github.com/v3/activity/notifications/#set-a-thread-subscription</remarks>
|
|
public Task<ThreadSubscription> SetThreadSubscription(int id, NewThreadSubscription threadSubscription)
|
|
{
|
|
Ensure.ArgumentNotNull(threadSubscription, "threadSubscription");
|
|
|
|
return ApiConnection.Put<ThreadSubscription>(ApiUrls.NotificationSubscription(id), threadSubscription);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deletes the authenticated user's subscription to a given thread.
|
|
/// </summary>
|
|
/// <param name="id">The Id of the thread to delete subscription from.</param>
|
|
/// <remarks>http://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription</remarks>
|
|
public Task DeleteThreadSubscription(int id)
|
|
{
|
|
return ApiConnection.Delete(ApiUrls.NotificationSubscription(id));
|
|
}
|
|
}
|
|
}
|