mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
added new overloads
This commit is contained in:
@@ -3,6 +3,12 @@ using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Watching API.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/activity/watching/">Watching API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
public interface IObservableWatchedClient
|
||||
{
|
||||
/// <summary>
|
||||
@@ -14,6 +20,14 @@ namespace Octokit.Reactive
|
||||
/// <returns>A <see cref="IObservable{User}"/> of <see cref="User"/>s watching the passed repository</returns>
|
||||
IObservable<User> GetAllWatchers(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated</exception>
|
||||
/// <returns>A <see cref="IObservable{User}"/> of <see cref="User"/>s watching the passed repository</returns>
|
||||
IObservable<User> GetAllWatchers(int repositoryId);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository
|
||||
/// </summary>
|
||||
@@ -24,6 +38,15 @@ namespace Octokit.Reactive
|
||||
/// <returns>A <see cref="IObservable{User}"/> of <see cref="User"/>s watching the passed repository</returns>
|
||||
IObservable<User> GetAllWatchers(string owner, string name, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="options">Options for changing the API's response.</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated</exception>
|
||||
/// <returns>A <see cref="IObservable{User}"/> of <see cref="User"/>s watching the passed repository</returns>
|
||||
IObservable<User> GetAllWatchers(int repositoryId, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watched <see cref="Repository"/>(ies) for the current user
|
||||
/// </summary>
|
||||
@@ -66,6 +89,14 @@ namespace Octokit.Reactive
|
||||
/// <returns>A <c>bool</c> representing the success of the operation</returns>
|
||||
IObservable<bool> CheckWatched(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Check if a repository is watched by the current authenticated user
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated</exception>
|
||||
/// <returns>A <c>bool</c> representing the success of the operation</returns>
|
||||
IObservable<bool> CheckWatched(int repositoryId);
|
||||
|
||||
/// <summary>
|
||||
/// Stars a repository for the authenticated user.
|
||||
/// </summary>
|
||||
@@ -75,6 +106,14 @@ namespace Octokit.Reactive
|
||||
/// <returns>A <c>bool</c> representing the success of starring</returns>
|
||||
IObservable<Subscription> WatchRepo(string owner, string name, NewSubscription newSubscription);
|
||||
|
||||
/// <summary>
|
||||
/// Stars a repository for the authenticated user.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="newSubscription">A <see cref="NewSubscription"/> instance describing the new subscription to create</param>
|
||||
/// <returns>A <c>bool</c> representing the success of starring</returns>
|
||||
IObservable<Subscription> WatchRepo(int repositoryId, NewSubscription newSubscription);
|
||||
|
||||
/// <summary>
|
||||
/// Unstars a repository for the authenticated user.
|
||||
/// </summary>
|
||||
@@ -84,5 +123,14 @@ namespace Octokit.Reactive
|
||||
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Unwatch",
|
||||
Justification = "Unwatch is consistent with the GitHub website")]
|
||||
IObservable<bool> UnwatchRepo(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Unstars a repository for the authenticated user.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <returns>A <c>bool</c> representing the success of the operation</returns>
|
||||
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Unwatch",
|
||||
Justification = "Unwatch is consistent with the GitHub website")]
|
||||
IObservable<bool> UnwatchRepo(int repositoryId);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,12 @@ using Octokit.Reactive.Internal;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Watching API.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/activity/watching/">Watching API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
public class ObservableWatchedClient : IObservableWatchedClient
|
||||
{
|
||||
private readonly IWatchedClient _client;
|
||||
@@ -32,6 +38,17 @@ namespace Octokit.Reactive
|
||||
return GetAllWatchers(owner, name, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated</exception>
|
||||
/// <returns>A <see cref="IObservable{User}"/> of <see cref="User"/>s watching the passed repository</returns>
|
||||
public IObservable<User> GetAllWatchers(int repositoryId)
|
||||
{
|
||||
return GetAllWatchers(repositoryId, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository
|
||||
/// </summary>
|
||||
@@ -49,6 +66,20 @@ namespace Octokit.Reactive
|
||||
return _connection.GetAndFlattenAllPages<User>(ApiUrls.Watchers(owner, name), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="options">Options for changing the API's response.</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated</exception>
|
||||
/// <returns>A <see cref="IObservable{User}"/> of <see cref="User"/>s watching the passed repository</returns>
|
||||
public IObservable<User> GetAllWatchers(int repositoryId, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<User>(ApiUrls.Watchers(repositoryId), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watched <see cref="Repository"/>(ies) for the current user
|
||||
/// </summary>
|
||||
@@ -115,6 +146,17 @@ namespace Octokit.Reactive
|
||||
return _client.CheckWatched(owner, name).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a repository is watched by the current authenticated user
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated</exception>
|
||||
/// <returns>A <c>bool</c> representing the success of the operation</returns>
|
||||
public IObservable<bool> CheckWatched(int repositoryId)
|
||||
{
|
||||
return _client.CheckWatched(repositoryId).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stars a repository for the authenticated user.
|
||||
/// </summary>
|
||||
@@ -126,10 +168,24 @@ namespace Octokit.Reactive
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNull(newSubscription, "newSubscription");
|
||||
|
||||
return _client.WatchRepo(owner, name, newSubscription).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stars a repository for the authenticated user.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="newSubscription">A <see cref="NewSubscription"/> instance describing the new subscription to create</param>
|
||||
/// <returns>A <c>bool</c> representing the success of starring</returns>
|
||||
public IObservable<Subscription> WatchRepo(int repositoryId, NewSubscription newSubscription)
|
||||
{
|
||||
Ensure.ArgumentNotNull(newSubscription, "newSubscription");
|
||||
|
||||
return _client.WatchRepo(repositoryId, newSubscription).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unstars a repository for the authenticated user.
|
||||
/// </summary>
|
||||
@@ -143,5 +199,15 @@ namespace Octokit.Reactive
|
||||
|
||||
return _client.UnwatchRepo(owner, name).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unstars a repository for the authenticated user.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <returns>A <c>bool</c> representing the success of the operation</returns>
|
||||
public IObservable<bool> UnwatchRepo(int repositoryId)
|
||||
{
|
||||
return _client.UnwatchRepo(repositoryId).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,14 @@ namespace Octokit
|
||||
/// <returns>A <see cref="IReadOnlyPagedCollection{User}"/> of <see cref="User"/>s watching the passed repository.</returns>
|
||||
Task<IReadOnlyList<User>> GetAllWatchers(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
||||
/// <returns>A <see cref="IReadOnlyPagedCollection{User}"/> of <see cref="User"/>s watching the passed repository.</returns>
|
||||
Task<IReadOnlyList<User>> GetAllWatchers(int repositoryId);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository.
|
||||
/// </summary>
|
||||
@@ -31,6 +39,15 @@ namespace Octokit
|
||||
/// <returns>A <see cref="IReadOnlyPagedCollection{User}"/> of <see cref="User"/>s watching the passed repository.</returns>
|
||||
Task<IReadOnlyList<User>> GetAllWatchers(string owner, string name, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="options">Options for changing API's response.</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
||||
/// <returns>A <see cref="IReadOnlyPagedCollection{User}"/> of <see cref="User"/>s watching the passed repository.</returns>
|
||||
Task<IReadOnlyList<User>> GetAllWatchers(int repositoryId, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watched <see cref="Repository"/>(ies) for the current user.
|
||||
/// </summary>
|
||||
@@ -82,6 +99,14 @@ namespace Octokit
|
||||
/// <returns>A <c>bool</c> representing the success of the operation</returns>
|
||||
Task<bool> CheckWatched(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Check if a repository is watched by the current authenticated user.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
||||
/// <returns>A <c>bool</c> representing the success of the operation</returns>
|
||||
Task<bool> CheckWatched(int repositoryId);
|
||||
|
||||
/// <summary>
|
||||
/// Watches a repository for the authenticated user.
|
||||
/// </summary>
|
||||
@@ -91,6 +116,14 @@ namespace Octokit
|
||||
/// <returns>A <c>bool</c> representing the success of watching</returns>
|
||||
Task<Subscription> WatchRepo(string owner, string name, NewSubscription newSubscription);
|
||||
|
||||
/// <summary>
|
||||
/// Watches a repository for the authenticated user.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="newSubscription">A <see cref="NewSubscription"/> instance describing the new subscription to create</param>
|
||||
/// <returns>A <c>bool</c> representing the success of watching</returns>
|
||||
Task<Subscription> WatchRepo(int repositoryId, NewSubscription newSubscription);
|
||||
|
||||
/// <summary>
|
||||
/// Unwatches a repository for the authenticated user.
|
||||
/// </summary>
|
||||
@@ -100,5 +133,14 @@ namespace Octokit
|
||||
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Unwatch",
|
||||
Justification = "Unwatch is consistent with the GitHub website")]
|
||||
Task<bool> UnwatchRepo(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Unwatches a repository for the authenticated user.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <returns>A <c>bool</c> representing the success of the operation</returns>
|
||||
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Unwatch",
|
||||
Justification = "Unwatch is consistent with the GitHub website")]
|
||||
Task<bool> UnwatchRepo(int repositoryId);
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,17 @@ namespace Octokit
|
||||
return GetAllWatchers(owner, name, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
||||
/// <returns>A <see cref="IReadOnlyPagedCollection{User}"/> of <see cref="User"/>s watching the passed repository.</returns>
|
||||
public Task<IReadOnlyList<User>> GetAllWatchers(int repositoryId)
|
||||
{
|
||||
return GetAllWatchers(repositoryId, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository.
|
||||
/// </summary>
|
||||
@@ -53,6 +64,20 @@ namespace Octokit
|
||||
return ApiConnection.GetAll<User>(ApiUrls.Watchers(owner, name), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="options">Options for changing API's response.</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
||||
/// <returns>A <see cref="IReadOnlyPagedCollection{User}"/> of <see cref="User"/>s watching the passed repository.</returns>
|
||||
public Task<IReadOnlyList<User>> GetAllWatchers(int repositoryId, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return ApiConnection.GetAll<User>(ApiUrls.Watchers(repositoryId), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watched <see cref="Repository"/>(ies) for the current user.
|
||||
/// </summary>
|
||||
@@ -137,6 +162,27 @@ namespace Octokit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a repository is watched by the current authenticated user.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
||||
/// <returns>A <c>bool</c> representing the success of the operation</returns>
|
||||
public async Task<bool> CheckWatched(int repositoryId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var endpoint = ApiUrls.Watched(repositoryId);
|
||||
var subscription = await ApiConnection.Get<Subscription>(endpoint).ConfigureAwait(false);
|
||||
|
||||
return subscription != null;
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Watches a repository for the authenticated user.
|
||||
/// </summary>
|
||||
@@ -153,6 +199,19 @@ namespace Octokit
|
||||
return ApiConnection.Put<Subscription>(ApiUrls.Watched(owner, name), newSubscription);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Watches a repository for the authenticated user.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="newSubscription">A <see cref="NewSubscription"/> instance describing the new subscription to create</param>
|
||||
/// <returns>A <c>bool</c> representing the success of watching</returns>
|
||||
public Task<Subscription> WatchRepo(int repositoryId, NewSubscription newSubscription)
|
||||
{
|
||||
Ensure.ArgumentNotNull(newSubscription, "newSubscription");
|
||||
|
||||
return ApiConnection.Put<Subscription>(ApiUrls.Watched(repositoryId), newSubscription);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unwatches a repository for the authenticated user.
|
||||
/// </summary>
|
||||
@@ -176,5 +235,25 @@ namespace Octokit
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unwatches a repository for the authenticated user.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <returns>A <c>bool</c> representing the success of the operation</returns>
|
||||
public async Task<bool> UnwatchRepo(int repositoryId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var endpoint = ApiUrls.Watched(repositoryId);
|
||||
var statusCode = await Connection.Delete(endpoint).ConfigureAwait(false);
|
||||
|
||||
return statusCode == HttpStatusCode.NoContent;
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to watch a repository (subscribe to repository's notifications). Called by the
|
||||
/// <see cref="IWatchedClient.WatchRepo"/> method.
|
||||
/// <see cref="IWatchedClient.WatchRepo(string,string,NewSubscription)"/> method.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// API: https://developer.github.com/v3/activity/watching/#set-a-repository-subscription
|
||||
@@ -19,7 +19,7 @@ namespace Octokit
|
||||
/// <remarks>
|
||||
/// If you would like to watch a repository, set subscribed to true. If you would like to ignore notifications
|
||||
/// made within a repository, set ignored to true. If you would like to stop watching a repository, delete the
|
||||
/// repository’s subscription completely using the <see cref="IWatchedClient.UnwatchRepo"/> method.
|
||||
/// repository’s subscription completely using the <see cref="IWatchedClient.UnwatchRepo(string,string)"/> method.
|
||||
/// </remarks>
|
||||
public bool Subscribed { get; set; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user