Implementing the rest of the Notifications API

This commit is contained in:
Dillon Buchanan
2014-08-17 11:03:32 -04:00
committed by Brendan Forster
parent 45e48e26f7
commit f45fc8e3ff
20 changed files with 795 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive;
namespace Octokit.Reactive
{
@@ -20,5 +21,95 @@ namespace Octokit.Reactive
/// <returns>A <see cref="IObservable{Notification}"/> of <see cref="Notification"/>.</returns>
IObservable<Notification> GetAllForRepository(string owner, string name);
/// <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>
/// <returns>A <see cref="IReadOnlyPagedCollection{Notification}"/> of <see cref="Notification"/>.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
IObservable<Notification> GetAllForCurrent(NotificationsRequest request);
/// <summary>
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
/// </summary>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="IReadOnlyPagedCollection{Notification}"/> of <see cref="Notification"/>.</returns>
IObservable<Notification> GetAllForRepository(string owner, string name, NotificationsRequest request);
/// <summary>
/// Marks all notifications as read.
/// </summary>
/// <remarks>http://developer.github.com/v3/activity/notifications/#mark-as-read</remarks>
/// <returns></returns>
IObservable<Unit> MarkAsRead();
/// <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>
/// <returns></returns>
IObservable<Unit> MarkAsRead(MarkAsReadRequest 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>
/// <returns></returns>
IObservable<Unit> MarkAsReadForRepository(string owner, string name);
/// <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="markAsRead">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>
/// <returns></returns>
IObservable<Unit> MarkAsReadForRepository(string owner, string name, MarkAsReadRequest markAsRead);
/// <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>
/// <returns>A <see cref="Notification"/> for the given Id.</returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
IObservable<Notification> Get(int 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>
/// <returns></returns>
IObservable<Unit> MarkAsRead(int 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>
/// <returns>A <see cref="ThreadSubscription"/> for the chosen thread.</returns>
IObservable<ThreadSubscription> GetThreadSubscription(int 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>
/// <returns></returns>
IObservable<ThreadSubscription> SetThreadSubscription(int id, NewThreadSubscription 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>
/// <returns></returns>
IObservable<Unit> DeleteThreadSubscription(int id);
}
}

View File

@@ -1,4 +1,6 @@
using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
@@ -6,12 +8,14 @@ namespace Octokit.Reactive
public class ObservableNotificationsClient : IObservableNotificationsClient
{
readonly IConnection _connection;
readonly INotificationsClient _notificationsClient;
public ObservableNotificationsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_connection = client.Connection;
_notificationsClient = client.Notification;
}
/// <summary>
@@ -24,6 +28,19 @@ namespace Octokit.Reactive
return _connection.GetAndFlattenAllPages<Notification>(ApiUrls.Notifications());
}
/// <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>
/// <returns>A <see cref="IReadOnlyPagedCollection{Notification}"/> of <see cref="Notification"/>.</returns>
public IObservable<Notification> GetAllForCurrent(NotificationsRequest request)
{
Ensure.ArgumentNotNull(request, "request");
return _connection.GetAndFlattenAllPages<Notification>(ApiUrls.Notifications(), request.ToParametersDictionary());
}
/// <summary>
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
/// </summary>
@@ -33,5 +50,122 @@ namespace Octokit.Reactive
{
return _connection.GetAndFlattenAllPages<Notification>(ApiUrls.Notifications(owner, name));
}
/// <summary>
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
/// </summary>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="IReadOnlyPagedCollection{Notification}"/> of <see cref="Notification"/>.</returns>
public IObservable<Notification> GetAllForRepository(string owner, string name, NotificationsRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(request, "request");
return _connection.GetAndFlattenAllPages<Notification>(ApiUrls.Notifications(owner, name), request.ToParametersDictionary());
}
/// <summary>
/// Marks all notifications as read.
/// </summary>
/// <remarks>http://developer.github.com/v3/activity/notifications/#mark-as-read</remarks>
/// <returns></returns>
public IObservable<Unit> MarkAsRead()
{
return _notificationsClient.MarkAsRead().ToObservable();
}
/// <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>
/// <returns></returns>
public IObservable<Unit> MarkAsRead(MarkAsReadRequest markAsReadRequest)
{
return _notificationsClient.MarkAsRead(markAsReadRequest).ToObservable();
}
/// <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>
/// <returns></returns>
public IObservable<Unit> MarkAsReadForRepository(string owner, string name)
{
return _notificationsClient.MarkAsReadForRepository(owner, name).ToObservable();
}
/// <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="markAsRead">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>
/// <returns></returns>
public IObservable<Unit> MarkAsReadForRepository(string owner, string name, MarkAsReadRequest markAsRead)
{
return _notificationsClient.MarkAsReadForRepository(owner, name, markAsRead).ToObservable();
}
/// <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>
/// <returns>A <see cref="Notification"/> for the given Id.</returns>
public IObservable<Notification> Get(int id)
{
return _notificationsClient.Get(id).ToObservable();
}
/// <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>
/// <returns></returns>
public IObservable<Unit> MarkAsRead(int id)
{
return _notificationsClient.MarkAsRead(id).ToObservable();
}
/// <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>
/// <returns>A <see cref="ThreadSubscription"/> for the chosen thread.</returns>
public IObservable<ThreadSubscription> GetThreadSubscription(int id)
{
return _notificationsClient.GetThreadSubscription(id).ToObservable();
}
/// <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>
/// <returns></returns>
public IObservable<ThreadSubscription> SetThreadSubscription(int id, NewThreadSubscription threadSubscription)
{
return _notificationsClient.SetThreadSubscription(id, threadSubscription).ToObservable();
}
/// <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>
/// <returns></returns>
public IObservable<Unit> DeleteThreadSubscription(int id)
{
return _notificationsClient.DeleteThreadSubscription(id).ToObservable();
}
}
}

View File

@@ -35,5 +35,111 @@ namespace Octokit.Tests.Clients
connection.Received().GetAll<Notification>(endpoint);
}
}
public class TheMarkAsRead
{
[Fact]
public void RequestsCorrectUrl()
{
var endpoint = new Uri("notifications", UriKind.Relative);
var connection = Substitute.For<IApiConnection>();
var client = new NotificationsClient(connection);
client.MarkAsRead();
connection.Received().Put(endpoint);
}
}
public class TheMarkAsReadForRepository
{
[Fact]
public void RequestsCorrectUrl()
{
var endpoint = new Uri("repos/banana/split/notifications", UriKind.Relative);
var connection = Substitute.For<IApiConnection>();
var client = new NotificationsClient(connection);
client.MarkAsReadForRepository("banana", "split");
connection.Received().Put(endpoint);
}
}
public class TheGetNotification
{
[Fact]
public void RequestsCorrectUrl()
{
var endpoint = new Uri("notifications/threads/1", UriKind.Relative);
var connection = Substitute.For<IApiConnection>();
var client = new NotificationsClient(connection);
client.Get(1);
connection.Received().Get<Notification>(endpoint);
}
}
public class TheMarkNotificationAsRead
{
[Fact]
public void RequestsCorrectUrl()
{
var endpoint = new Uri("notifications/threads/1", UriKind.Relative);
var connection = Substitute.For<IApiConnection>();
var client = new NotificationsClient(connection);
client.MarkAsRead(1);
connection.Received().Patch(endpoint);
}
}
public class TheGetThreadSubscription
{
[Fact]
public void RequestsCorrectUrl()
{
var endpoint = new Uri("notifications/threads/1/subscription", UriKind.Relative);
var connection = Substitute.For<IApiConnection>();
var client = new NotificationsClient(connection);
client.GetThreadSubscription(1);
connection.Received().Get<ThreadSubscription>(endpoint);
}
}
public class TheSetThreadSubscription
{
[Fact]
public void RequestsCorrectUrl()
{
var endpoint = new Uri("notifications/threads/1/subscription", UriKind.Relative);
var connection = Substitute.For<IApiConnection>();
var client = new NotificationsClient(connection);
var data = new NewThreadSubscription();
client.SetThreadSubscription(1, data);
connection.Received().Put<ThreadSubscription>(endpoint, data);
}
}
public class TheDeleteThreadSubscription
{
[Fact]
public void RequestsCorrectUrl()
{
var endpoint = new Uri("notifications/threads/1/subscription", UriKind.Relative);
var connection = Substitute.For<IApiConnection>();
var client = new NotificationsClient(connection);
client.DeleteThreadSubscription(1);
connection.Received().Delete(endpoint);
}
}
}
}

View File

@@ -20,11 +20,102 @@ namespace Octokit
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
Task<IReadOnlyList<Notification>> GetAllForCurrent();
/// <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>
/// <returns>A <see cref="IReadOnlyPagedCollection{Notification}"/> of <see cref="Notification"/>.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
Task<IReadOnlyList<Notification>> GetAllForCurrent(NotificationsRequest request);
/// <summary>
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
/// </summary>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="IReadOnlyPagedCollection{Notification}"/> of <see cref="Notification"/>.</returns>
Task<IReadOnlyList<Notification>> GetAllForRepository(string owner, string name);
/// <summary>
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
/// </summary>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="IReadOnlyPagedCollection{Notification}"/> of <see cref="Notification"/>.</returns>
Task<IReadOnlyList<Notification>> GetAllForRepository(string owner, string name, NotificationsRequest request);
/// <summary>
/// Marks all notifications as read.
/// </summary>
/// <remarks>http://developer.github.com/v3/activity/notifications/#mark-as-read</remarks>
/// <returns></returns>
Task MarkAsRead();
/// <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>
/// <returns></returns>
Task MarkAsRead(MarkAsReadRequest 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>
/// <returns></returns>
Task MarkAsReadForRepository(string owner, string name);
/// <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="markAsRead">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>
/// <returns></returns>
Task MarkAsReadForRepository(string owner, string name, MarkAsReadRequest markAsRead);
/// <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>
/// <returns>A <see cref="Notification"/> for the given Id.</returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
Task<Notification> Get(int 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>
/// <returns></returns>
Task MarkAsRead(int 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>
/// <returns>A <see cref="ThreadSubscription"/> for the chosen thread.</returns>
Task<ThreadSubscription> GetThreadSubscription(int 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>
/// <returns></returns>
Task<ThreadSubscription> SetThreadSubscription(int id, NewThreadSubscription 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>
/// <returns></returns>
Task DeleteThreadSubscription(int id);
}
}

View File

@@ -29,6 +29,18 @@ namespace Octokit
return ApiConnection.GetAll<Notification>(ApiUrls.Notifications());
}
/// <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>
/// <returns>A <see cref="IReadOnlyPagedCollection{Notification}"/> of <see cref="Notification"/>.</returns>
public Task<IReadOnlyList<Notification>> GetAllForCurrent(NotificationsRequest request)
{
Ensure.ArgumentNotNull(request, "request");
return ApiConnection.GetAll<Notification>(ApiUrls.Notifications(), request.ToParametersDictionary());
}
/// <summary>
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
/// </summary>
@@ -36,7 +48,134 @@ namespace Octokit
/// <returns>A <see cref="IReadOnlyPagedCollection{Notification}"/> of <see cref="Notification"/>.</returns>
public Task<IReadOnlyList<Notification>> GetAllForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return ApiConnection.GetAll<Notification>(ApiUrls.Notifications(owner, name));
}
/// <summary>
/// Retrieves all of the <see cref="Notification"/>s for the current user specific to the specified repository.
/// </summary>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="IReadOnlyPagedCollection{Notification}"/> of <see cref="Notification"/>.</returns>
public Task<IReadOnlyList<Notification>> GetAllForRepository(string owner, string name, NotificationsRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(request, "request");
return ApiConnection.GetAll<Notification>(ApiUrls.Notifications(owner, name), request.ToParametersDictionary());
}
/// <summary>
/// Marks all notifications as read.
/// </summary>
/// <remarks>http://developer.github.com/v3/activity/notifications/#mark-as-read</remarks>
/// <returns></returns>
public Task MarkAsRead()
{
return ApiConnection.Put(ApiUrls.Notifications());
}
/// <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>
/// <returns></returns>
public Task MarkAsRead(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>
/// <returns></returns>
public Task MarkAsReadForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return ApiConnection.Put(ApiUrls.Notifications(owner, name));
}
/// <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="markAsRead">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>
/// <returns></returns>
public Task MarkAsReadForRepository(string owner, string name, MarkAsReadRequest markAsRead)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return ApiConnection.Put<object>(ApiUrls.Notifications(owner, name), markAsRead);
}
/// <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>
/// <returns>A <see cref="Notification"/> for the given Id.</returns>
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>
/// <returns></returns>
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>
/// <returns>A <see cref="ThreadSubscription"/> for the chosen thread.</returns>
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>
/// <returns></returns>
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>
/// <returns></returns>
public Task DeleteThreadSubscription(int id)
{
return ApiConnection.Delete(ApiUrls.NotificationSubscription(id));
}
}
}

View File

@@ -175,6 +175,26 @@ namespace Octokit
return "repos/{0}/{1}/notifications".FormatUri(owner, name);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the specified notification.
/// </summary>
/// <param name="id">The Id of the notification.</param>
/// <returns></returns>
public static Uri Notification(int id)
{
return "notifications/threads/{0}".FormatUri(id);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the specified notification's subscription status.
/// </summary>
/// <param name="id">The Id of the notification.</param>
/// <returns></returns>
public static Uri NotificationSubscription(int id)
{
return "notifications/threads/{0}/subscription".FormatUri(id);
}
/// <summary>
/// Returns the <see cref="Uri"/> that returns all of the issues across all the authenticated users visible
/// repositories including owned repositories, member repositories, and organization repositories:

View File

@@ -236,6 +236,18 @@ namespace Octokit
return response.BodyAsObject;
}
/// <summary>
/// Updates the API resource at the specified URI.
/// </summary>
/// <param name="uri">URI of the API resource to patch</param>
/// <returns>A <see cref="Task"/> for the request's execution.</returns>
public Task Patch(Uri uri)
{
Ensure.ArgumentNotNull(uri, "uri");
return Connection.Patch(uri);
}
/// <summary>
/// Updates the API resource at the specified URI.
/// </summary>

View File

@@ -257,6 +257,25 @@ namespace Octokit
return Run<T>(request,cancellationToken);
}
/// <summary>
/// Performs an asynchronous HTTP PATCH request.
/// </summary>
/// <param name="uri">URI endpoint to send request to</param>
/// <returns><seealso cref="IResponse"/> representing the received HTTP response</returns>
public async Task<HttpStatusCode> Patch(Uri uri)
{
Ensure.ArgumentNotNull(uri, "uri");
var request = new Request
{
Method = HttpVerb.Patch,
BaseAddress = BaseAddress,
Endpoint = uri
};
var response = await Run<object>(request, CancellationToken.None);
return response.StatusCode;
}
/// <summary>
/// Performs an asynchronous HTTP PUT request that expects an empty response.
/// </summary>

View File

@@ -142,6 +142,13 @@ namespace Octokit
/// <exception cref="ApiException">Thrown when an API error occurs.</exception>
Task<T> Put<T>(Uri uri, object data, string twoFactorAuthenticationCode);
/// <summary>
/// Updates the API resource at the specified URI.
/// </summary>
/// <param name="uri">URI of the API resource to patch</param>
/// <returns>A <see cref="Task"/> for the request's execution.</returns>
Task Patch(Uri uri);
/// <summary>
/// Updates the API resource at the specified URI.
/// </summary>

View File

@@ -45,6 +45,13 @@ namespace Octokit
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
Task<IResponse<T>> Get<T>(Uri uri, IDictionary<string, string> parameters, string accepts, CancellationToken cancellationToken);
/// <summary>
/// Performs an asynchronous HTTP PATCH request.
/// </summary>
/// <param name="uri">URI endpoint to send request to</param>
/// <returns><seealso cref="IResponse"/> representing the received HTTP response</returns>
Task<HttpStatusCode> Patch(Uri uri);
/// <summary>
/// Performs an asynchronous HTTP PATCH request.
/// Attempts to map the response body to an object of type <typeparamref name="T"/>

View File

@@ -0,0 +1,20 @@
using System;
using System.Diagnostics;
using Octokit.Internal;
namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class MarkAsReadRequest : RequestParameters
{
public MarkAsReadRequest()
{
LastReadAt = null;
}
/// <summary>
/// Describes the last point that notifications were checked. Anything updated since this time will not be updated.
/// </summary>
public DateTimeOffset? LastReadAt { get; set; }
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Diagnostics;
using System.Globalization;
namespace Octokit
{
/// <summary>
/// Represents updatable fields for a users subscription to a given thread
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class NewThreadSubscription
{
/// <summary>
/// Determines if notifications should be received from this thread
/// </summary>
public bool Subscribed { get; set; }
/// <summary>
/// Determines if all notifications should be blocked from this thread
/// </summary>
public bool Ignored { get; set; }
internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "Subscribed: {0} Ignored: {1}", Subscribed, Ignored);
}
}
}
}

View File

@@ -0,0 +1,46 @@
using System;
using System.Diagnostics;
using System.Globalization;
namespace Octokit
{
/// <summary>
/// Specifies the parameters to filter notifications by
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class NotificationsRequest : RequestParameters
{
/// <summary>
/// If true, show notifications marked as read. Default: false
/// </summary>
public bool All { get; set; }
/// <summary>
/// If true, only shows notifications in which the user is directly participating or mentioned. Default: false
/// </summary>
public bool Participating { get; set; }
/// <summary>
/// Filters out any notifications updated before the given time. Default: Time.now
/// </summary>
public DateTimeOffset Since { get; set; }
/// <summary>
/// Construct a <see cref="NotificationsRequest"/> object
/// </summary>
public NotificationsRequest()
{
All = false;
Participating = false;
Since = DateTimeOffset.Now;
}
internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "All: {0}, Participating: {1}, Since: {2}", All, Participating, Since);
}
}
}
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Diagnostics;
using System.Globalization;
namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class ThreadSubscription
{
/// <summary>
/// Determines if notifications should be received from this repository.
/// </summary>
public bool Subscribed { get; set; }
/// <summary>
/// Determines if all notifications should be blocked from this repository.
/// </summary>
public bool Ignored { get; set; }
/// <summary>
/// Url of the label
/// </summary>
public string Reason { get; set; }
/// <summary>
/// The <see cref="DateTimeOffset"/> for when this <see cref="Subscription"/> was created.
/// </summary>
public DateTimeOffset CreatedAt { get; set; }
/// <summary>
/// The API URL for this <see cref="Subscription"/>.
/// </summary>
public Uri Url { get; set; }
/// <summary>
/// The API URL for this thread.
/// </summary>
public Uri ThreadUrl { get; set; }
internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "Subscribed: {0}", Subscribed);
}
}
}
}

View File

@@ -340,6 +340,10 @@
<Compile Include="Models\Request\CommitRequest.cs" />
<Compile Include="Models\Response\RepositoryPermissions.cs" />
<Compile Include="Models\Request\NewRelease.cs" />
<Compile Include="Models\Request\NotificationsRequest.cs" />
<Compile Include="Models\Response\ThreadSubscription.cs" />
<Compile Include="Models\Request\MarkAsReadRequest.cs" />
<Compile Include="Models\Request\NewThreadSubscription.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -350,6 +350,10 @@
<Compile Include="Models\Request\CommitRequest.cs" />
<Compile Include="Models\Response\RepositoryPermissions.cs" />
<Compile Include="Models\Request\NewRelease.cs" />
<Compile Include="Models\Request\NotificationsRequest.cs" />
<Compile Include="Models\Response\ThreadSubscription.cs" />
<Compile Include="Models\Request\MarkAsReadRequest.cs" />
<Compile Include="Models\Request\NewThreadSubscription.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>

View File

@@ -345,6 +345,10 @@
<Compile Include="Models\Request\CommitRequest.cs" />
<Compile Include="Models\Response\RepositoryPermissions.cs" />
<Compile Include="Models\Request\NewRelease.cs" />
<Compile Include="Models\Request\NotificationsRequest.cs" />
<Compile Include="Models\Response\ThreadSubscription.cs" />
<Compile Include="Models\Request\MarkAsReadRequest.cs" />
<Compile Include="Models\Request\NewThreadSubscription.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -338,6 +338,10 @@
<Compile Include="Models\Request\OrganizationUpdate.cs" />
<Compile Include="Models\Response\RepositoryPermissions.cs" />
<Compile Include="Models\Request\NewRelease.cs" />
<Compile Include="Models\Request\NotificationsRequest.cs" />
<Compile Include="Models\Response\ThreadSubscription.cs" />
<Compile Include="Models\Request\MarkAsReadRequest.cs" />
<Compile Include="Models\Request\NewThreadSubscription.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">

View File

@@ -342,6 +342,10 @@
<Compile Include="Models\Request\CommitRequest.cs" />
<Compile Include="Models\Response\RepositoryPermissions.cs" />
<Compile Include="Models\Request\NewRelease.cs" />
<Compile Include="Models\Request\NotificationsRequest.cs" />
<Compile Include="Models\Response\ThreadSubscription.cs" />
<Compile Include="Models\Request\MarkAsReadRequest.cs" />
<Compile Include="Models\Request\NewThreadSubscription.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">

View File

@@ -75,11 +75,14 @@
<Compile Include="Helpers\HttpClientExtensions.cs" />
<Compile Include="Helpers\SerializeNullAttribute.cs" />
<Compile Include="Http\ProductHeaderValue.cs" />
<Compile Include="Models\Request\MarkAsReadRequest.cs" />
<Compile Include="Models\Request\NewDeployKey.cs" />
<Compile Include="Models\Request\NewRelease.cs" />
<Compile Include="Models\Request\NotificationsRequest.cs" />
<Compile Include="Models\Request\PublicKey.cs" />
<Compile Include="Models\Request\CommitRequest.cs" />
<Compile Include="Models\Response\RepositoryPermissions.cs" />
<Compile Include="Models\Request\NewThreadSubscription.cs" />
<Compile Include="Models\Response\DeployKey.cs" />
<Compile Include="Models\Request\OauthLoginRequest.cs" />
<Compile Include="Models\Request\OauthTokenRequest.cs" />
@@ -179,6 +182,7 @@
<Compile Include="Models\Response\SearchRepositoryResult.cs" />
<Compile Include="Models\Response\SearchUsersResult.cs" />
<Compile Include="Models\Response\Subscription.cs" />
<Compile Include="Models\Response\ThreadSubscription.cs" />
<Compile Include="Models\Response\TreeItem.cs" />
<Compile Include="Models\Response\TreeResponse.cs" />
<Compile Include="Models\Response\Activity.cs" />