using System;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
///
/// A client for GitHub's Reactions API.
///
///
/// See the Reactions API documentation for more information.
///
public class ObservableIssueReactionsClient : IObservableIssueReactionsClient
{
readonly IIssueReactionsClient _client;
readonly IConnection _connection;
public ObservableIssueReactionsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));
_client = client.Reaction.Issue;
_connection = client.Connection;
}
///
/// List reactions for a specified Issue
///
/// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue
/// The owner of the repository
/// The name of the repository
/// The issue id
public IObservable GetAll(string owner, string name, int number)
{
return GetAll(owner, name, number, ApiOptions.None);
}
///
/// List reactions for a specified Issue
///
/// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue
/// The owner of the repository
/// The name of the repository
/// The issue id
/// Options for changing the API response
public IObservable GetAll(string owner, string name, int number, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.IssueReactions(owner, name, number), null, AcceptHeaders.ReactionsPreview, options);
}
///
/// List reactions for a specified Issue.
///
/// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue
/// The Id of the repository
/// The issue id
public IObservable GetAll(long repositoryId, int number)
{
return GetAll(repositoryId, number, ApiOptions.None);
}
///
/// List reactions for a specified Issue.
///
/// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue
/// The Id of the repository
/// The issue id
/// Options for changing the API response
public IObservable GetAll(long repositoryId, int number, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.IssueReactions(repositoryId, number), null, AcceptHeaders.ReactionsPreview, options);
}
///
/// Creates a reaction for a specified Issue
///
/// https://developer.github.com/v3/reactions/#create-reaction-for-an-issue
/// The owner of the repository
/// The name of the repository
/// The issue id
/// The reaction to create
public IObservable Create(string owner, string name, int number, NewReaction reaction)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(reaction, nameof(reaction));
return _client.Create(owner, name, number, reaction).ToObservable();
}
///
/// Creates a reaction for a specified Issue.
///
/// https://developer.github.com/v3/reactions/#create-reaction-for-an-issue
/// The Id of the repository
/// The issue id
/// The reaction to create
public IObservable Create(long repositoryId, int number, NewReaction reaction)
{
Ensure.ArgumentNotNull(reaction, nameof(reaction));
return _client.Create(repositoryId, number, reaction).ToObservable();
}
}
}