using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
public class ObservableFollowersClient : IObservableFollowersClient
{
readonly IFollowersClient _client;
readonly IConnection _connection;
///
/// Initializes a new User Followers API client.
///
/// An used to make the requests
public ObservableFollowersClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.User.Followers;
_connection = client.Connection;
}
///
/// List the authenticated user’s followers
///
///
/// See the API documentation for more information.
///
/// A of s that follow the authenticated user.
public IObservable GetAllForCurrent()
{
return GetAllForCurrent(ApiOptions.None);
}
///
/// List the authenticated user’s followers
///
/// Options for changing the API response
///
/// See the API documentation for more information.
///
/// A of s that follow the authenticated user.
public IObservable GetAllForCurrent(ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.Followers(), options);
}
///
/// List a user’s followers
///
/// The login name for the user
///
/// See the API documentation for more information.
///
/// A of s that follow the passed user.
public IObservable GetAll(string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
return GetAll(login, ApiOptions.None);
}
///
/// List a user’s followers
///
/// The login name for the user
/// Options for changing the API response
///
/// See the API documentation for more information.
///
/// A of s that follow the passed user.
public IObservable GetAll(string login, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.Followers(login), options);
}
///
/// List who the authenticated user is following
///
///
/// See the API documentation for more information.
///
/// A of s that the authenticated user follows.
public IObservable GetAllFollowingForCurrent()
{
return GetAllFollowingForCurrent(ApiOptions.None);
}
///
/// List who the authenticated user is following
///
/// Options for changing the API response
///
/// See the API documentation for more information.
///
/// A of s that the authenticated user follows.
public IObservable GetAllFollowingForCurrent(ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.Following(), options);
}
///
/// List who a user is following
///
/// The login name of the user
///
/// See the API documentation for more information.
///
/// A of s that the passed user follows.
public IObservable GetAllFollowing(string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
return GetAllFollowing(login, ApiOptions.None);
}
///
/// List who a user is following
///
/// The login name of the user
/// Options for changing the API response
///
/// See the API documentation for more information.
///
/// A of s that the passed user follows.
public IObservable GetAllFollowing(string login, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.Following(login), options);
}
///
/// Check if the authenticated user follows another user
///
/// The login name of the other user
///
/// See the API documentation for more information.
///
/// A bool representing the success of the operation.
public IObservable IsFollowingForCurrent(string following)
{
Ensure.ArgumentNotNullOrEmptyString(following, "following");
return _client.IsFollowingForCurrent(following).ToObservable();
}
///
/// Check if one user follows another user
///
/// The login name of the user
/// The login name of the other user
///
/// See the API documentation for more information.
///
/// A bool representing the success of the operation.
public IObservable IsFollowing(string login, string following)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
Ensure.ArgumentNotNullOrEmptyString(following, "following");
return _client.IsFollowing(login, following).ToObservable();
}
///
/// Follow a user
///
/// The login name of the user to follow
///
/// See the API documentation for more information.
///
/// A bool representing the success of the operation.
public IObservable Follow(string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
return _client.Follow(login).ToObservable();
}
///
/// Unfollow a user
///
/// The login name of the user to unfollow
///
/// See the API documentation for more information.
///
///
public IObservable Unfollow(string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
return _client.Unfollow(login).ToObservable();
}
}
}