using System; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { public class ObservableWatchedClient : IObservableWatchedClient { private readonly IWatchedClient _client; private readonly IConnection _connection; public ObservableWatchedClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _client = client.Activity.Watching; _connection = client.Connection; } /// /// Retrieves all of the watchers for the passed repository /// /// The owner of the repository /// The name of the repository /// Thrown if the client is not authenticated /// A of s watching the passed repository public IObservable GetAllWatchers(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return GetAllWatchers(owner, name, ApiOptions.None); } /// /// Retrieves all of the watchers for the passed repository /// /// The owner of the repository /// The name of the repository /// Options for changing the API's response. /// Thrown if the client is not authenticated /// A of s watching the passed repository public IObservable GetAllWatchers(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.Watchers(owner, name), options); } /// /// Retrieves all of the watched (ies) for the current user /// /// Thrown if the client is not authenticated /// A of public IObservable GetAllForCurrent() { return GetAllForCurrent(ApiOptions.None); } /// /// Retrieves all of the watched (ies) for the current user /// /// Options for changing the API's response. /// Thrown if the client is not authenticated /// A of public IObservable GetAllForCurrent(ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.Watched(), options); } /// /// Retrieves all of the (ies) watched by the specified user /// /// The login of the user /// Thrown if the client is not authenticated /// A watched by the specified user public IObservable GetAllForUser(string user) { Ensure.ArgumentNotNullOrEmptyString(user, "user"); return GetAllForUser(user, ApiOptions.None); } /// /// Retrieves all of the (ies) watched by the specified user /// /// The login of the user /// Options for changing the API's response. /// Thrown if the client is not authenticated /// A watched by the specified user public IObservable GetAllForUser(string user, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.WatchedByUser(user)); } /// /// Check if a repository is watched by the current authenticated user /// /// The owner of the repository /// The name of the repository /// Thrown if the client is not authenticated /// A bool representing the success of the operation public IObservable CheckWatched(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _client.CheckWatched(owner, name).ToObservable(); } /// /// Stars a repository for the authenticated user. /// /// The owner of the repository to star /// The name of the repository to star /// A instance describing the new subscription to create /// A bool representing the success of starring public IObservable WatchRepo(string owner, string name, NewSubscription newSubscription) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _client.WatchRepo(owner, name, newSubscription).ToObservable(); } /// /// Unstars a repository for the authenticated user. /// /// The owner of the repository to unstar /// The name of the repository to unstar /// A bool representing the success of the operation public IObservable UnwatchRepo(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _client.UnwatchRepo(owner, name).ToObservable(); } } }