using System;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
///
/// A client for GitHub's Activity Starring API.
///
///
/// See the Activity Starring API documentation for more information.
///
public class ObservableStarredClient : IObservableStarredClient
{
private readonly IStarredClient _client;
private readonly IConnection _connection;
public ObservableStarredClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));
_client = client.Activity.Starring;
_connection = client.Connection;
}
///
/// Retrieves all of the stargazers for the passed repository
///
/// The owner of the repository
/// The name of the repository
/// Thrown if the client is not authenticated
public IObservable GetAllStargazers(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return GetAllStargazers(owner, name, ApiOptions.None);
}
///
/// Retrieves all of the stargazers for the passed repository
///
/// The Id of the repository
/// Thrown if the client is not authenticated
public IObservable GetAllStargazers(long repositoryId)
{
return GetAllStargazers(repositoryId, ApiOptions.None);
}
///
/// Retrieves all of the stargazers for the passed 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 IObservable GetAllStargazers(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.Stargazers(owner, name), options);
}
///
/// Retrieves all of the stargazers for the passed repository
///
/// The Id of the repository
/// Options for changing the API response
/// Thrown if the client is not authenticated
public IObservable GetAllStargazers(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.Stargazers(repositoryId), options);
}
///
/// Retrieves all of the stargazers for the passed repository with star creation timestamps.
///
/// The owner of the repository
/// The name of the repository
/// Thrown if the client is not authenticated.
public IObservable GetAllStargazersWithTimestamps(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return GetAllStargazersWithTimestamps(owner, name, ApiOptions.None);
}
///
/// Retrieves all of the stargazers for the passed repository with star creation timestamps.
///
/// The Id of the repository
/// Thrown if the client is not authenticated.
public IObservable GetAllStargazersWithTimestamps(long repositoryId)
{
return GetAllStargazersWithTimestamps(repositoryId, ApiOptions.None);
}
///
/// Retrieves all of the stargazers for the passed repository with star creation timestamps.
///
/// The owner of the repository
/// The name of the repository
/// Options for changing the API response
/// Thrown if the client is not authenticated.
public IObservable GetAllStargazersWithTimestamps(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.Stargazers(owner, name), null, AcceptHeaders.StarCreationTimestamps, options);
}
///
/// Retrieves all of the stargazers for the passed repository with star creation timestamps.
///
/// The Id of the repository
/// Options for changing the API response
/// Thrown if the client is not authenticated.
public IObservable GetAllStargazersWithTimestamps(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.Stargazers(repositoryId), null, AcceptHeaders.StarCreationTimestamps, options);
}
///
/// Retrieves all of the starred (ies) for the current user
///
/// Thrown if the client is not authenticated
public IObservable GetAllForCurrent()
{
return GetAllForCurrent(ApiOptions.None);
}
///
/// Retrieves all of the starred (ies) for the current user
///
/// Thrown if the client is not authenticated
public IObservable GetAllForCurrent(ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), options);
}
///
/// Retrieves all of the starred (ies) for the current user with star creation timestamps.
///
/// Thrown if the client is not authenticated.
public IObservable GetAllForCurrentWithTimestamps()
{
return GetAllForCurrentWithTimestamps(ApiOptions.None);
}
///
/// Retrieves all of the starred (ies) for the current user with star creation timestamps.
///
/// Thrown if the client is not authenticated.
public IObservable GetAllForCurrentWithTimestamps(ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), null, AcceptHeaders.StarCreationTimestamps, options);
}
///
/// Retrieves all of the starred (ies) for the current user
///
/// Star-specific request parameters that sort the results
/// Thrown if the client is not authenticated
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public IObservable GetAllForCurrent(StarredRequest request)
{
Ensure.ArgumentNotNull(request, nameof(request));
return GetAllForCurrent(request, ApiOptions.None);
}
///
/// Retrieves all of the starred (ies) for the current user
///
/// Star-specific request parameters that sort the results
/// Options for changing the API response
/// Thrown if the client is not authenticated
public IObservable GetAllForCurrent(StarredRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), request.ToParametersDictionary(), options);
}
///
/// Retrieves all of the starred (ies) for the current user with star creation timestamps.
///
/// Star-specific request parameters that sort the results
/// Thrown if the client is not authenticated.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public IObservable GetAllForCurrentWithTimestamps(StarredRequest request)
{
Ensure.ArgumentNotNull(request, nameof(request));
return GetAllForCurrentWithTimestamps(request, ApiOptions.None);
}
///
/// Retrieves all of the starred (ies) for the current user with star creation timestamps.
///
/// Star-specific request parameters that sort the results
/// Options for changing the API response
/// Thrown if the client is not authenticated.
public IObservable GetAllForCurrentWithTimestamps(StarredRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps, options);
}
///
/// Retrieves all of the (ies) starred by the specified user
///
/// The login of the user
/// Thrown if the client is not authenticated
public IObservable GetAllForUser(string user)
{
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
return GetAllForUser(user, ApiOptions.None);
}
///
/// Retrieves all of the (ies) starred by the specified user
///
/// The login of the user
/// Options for changing the API response
/// Thrown if the client is not authenticated
public IObservable GetAllForUser(string user, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), options);
}
///
/// Retrieves all of the (ies) starred by the specified user with star creation timestamps.
///
/// The login of the user
/// Thrown if the client is not authenticated.
public IObservable GetAllForUserWithTimestamps(string user)
{
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
return GetAllForUserWithTimestamps(user, ApiOptions.None);
}
///
/// Retrieves all of the (ies) starred by the specified user with star creation timestamps.
///
/// The login of the user
/// Options for changing the API response
/// Thrown if the client is not authenticated.
public IObservable GetAllForUserWithTimestamps(string user, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), null, AcceptHeaders.StarCreationTimestamps, options);
}
///
/// Retrieves all of the (ies) starred by the specified user
///
/// The login of the user
/// Star-specific request parameters that sort the results
/// Thrown if the client is not authenticated
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public IObservable GetAllForUser(string user, StarredRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
Ensure.ArgumentNotNull(request, nameof(request));
return GetAllForUser(user, request, ApiOptions.None);
}
///
/// Retrieves all of the (ies) starred by the specified user
///
/// The login of the user
/// Star-specific request parameters that sort the results
/// Options for changing the API response
/// Thrown if the client is not authenticated
public IObservable GetAllForUser(string user, StarredRequest request, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), options);
}
///
/// Retrieves all of the (ies) starred by the specified user with star creation timestamps.
///
/// The login of the user
/// Star-specific request parameters that sort the results
/// Thrown if the client is not authenticated.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public IObservable GetAllForUserWithTimestamps(string user, StarredRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
Ensure.ArgumentNotNull(request, nameof(request));
return GetAllForUserWithTimestamps(user, request, ApiOptions.None);
}
///
/// Retrieves all of the (ies) starred by the specified user with star creation timestamps.
///
/// The login of the user
/// Star-specific request parameters that sort the results
/// Options for changing the API response
/// Thrown if the client is not authenticated.
public IObservable GetAllForUserWithTimestamps(string user, StarredRequest request, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps, options);
}
///
/// Check if a repository is starred by the current authenticated user
///
/// The owner of the repository
/// The name of the repository
/// Thrown if the client is not authenticated.
public IObservable CheckStarred(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return _client.CheckStarred(owner, name).ToObservable();
}
///
/// Stars a repository for the authenticated user
///
/// The owner of the repository to star
/// The name of the repository to star
public IObservable StarRepo(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return _client.StarRepo(owner, name).ToObservable();
}
///
/// Unstars a repository for the authenticated user
///
/// The owner of the repository to unstar
/// The name of the repository to unstar
public IObservable RemoveStarFromRepo(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return _client.RemoveStarFromRepo(owner, name).ToObservable();
}
}
}