using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
///
/// A client for GitHub's Issue Comments API.
///
///
/// See the Issue Comments API documentation for more information.
///
public class ObservableIssueCommentsClient : IObservableIssueCommentsClient
{
readonly IIssueCommentsClient _client;
readonly IConnection _connection;
public ObservableIssueCommentsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));
_client = client.Issue.Comment;
_connection = client.Connection;
}
///
/// Gets a single Issue Comment by id.
///
/// http://developer.github.com/v3/issues/comments/#get-a-single-comment
/// The owner of the repository
/// The name of the repository
/// The issue comment id
public IObservable Get(string owner, string name, long commentId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return _client.Get(owner, name, commentId).ToObservable();
}
///
/// Gets a single Issue Comment by id.
///
/// http://developer.github.com/v3/issues/comments/#get-a-single-comment
/// The Id of the repository
/// The issue comment id
public IObservable Get(long repositoryId, long commentId)
{
return _client.Get(repositoryId, commentId).ToObservable();
}
///
/// Gets Issue Comments for a repository.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
/// The owner of the repository
/// The name of the repository
public IObservable GetAllForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return GetAllForRepository(owner, name, ApiOptions.None);
}
///
/// Gets Issue Comments for a repository.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
/// The Id of the repository
public IObservable GetAllForRepository(long repositoryId)
{
return GetAllForRepository(repositoryId, ApiOptions.None);
}
///
/// Gets Issue Comments for a repository.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
/// The owner of the repository
/// The name of the repository
/// Options for changing the API response
public IObservable GetAllForRepository(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));
return GetAllForRepository(owner, name, new IssueCommentRequest(), options);
}
///
/// Gets Issue Comments for a repository.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
/// The Id of the repository
/// Options for changing the API response
public IObservable GetAllForRepository(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return GetAllForRepository(repositoryId, new IssueCommentRequest(), options);
}
///
/// Gets Issue Comments for a repository.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
/// The owner of the repository
/// The name of the repository
/// The sorting parameters
public IObservable GetAllForRepository(string owner, string name, IssueCommentRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(request, nameof(request));
return GetAllForRepository(owner, name, request, ApiOptions.None);
}
///
/// Gets Issue Comments for a repository.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
/// The Id of the repository
/// The sorting parameters
public IObservable GetAllForRepository(long repositoryId, IssueCommentRequest request)
{
Ensure.ArgumentNotNull(request, nameof(request));
return GetAllForRepository(repositoryId, request, ApiOptions.None);
}
///
/// Gets Issue Comments for a repository.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
/// The owner of the repository
/// The name of the repository
/// The sorting parameters
/// Options for changing the API response
public IObservable GetAllForRepository(string owner, string name, IssueCommentRequest request, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(owner, name), request.ToParametersDictionary(), options);
}
///
/// Gets Issue Comments for a repository.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
/// The Id of the repository
/// The sorting parameters
/// Options for changing the API response
public IObservable GetAllForRepository(long repositoryId, IssueCommentRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(repositoryId), request.ToParametersDictionary(), options);
}
///
/// Gets Issue Comments for a specified Issue.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
/// The owner of the repository
/// The name of the repository
/// The issue number
public IObservable GetAllForIssue(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return GetAllForIssue(owner, name, number, ApiOptions.None);
}
///
/// Gets Issue Comments for a specified Issue.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
/// The Id of the repository
/// The issue number
public IObservable GetAllForIssue(long repositoryId, int number)
{
return GetAllForIssue(repositoryId, number, ApiOptions.None);
}
///
/// Gets Issue Comments for a specified Issue.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
/// The owner of the repository
/// The name of the repository
/// The issue number
/// Options for changing the API response
public IObservable GetAllForIssue(string owner, string name, int number, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));
return GetAllForIssue(owner, name, number, new IssueCommentRequest(), options);
}
///
/// Gets Issue Comments for a specified Issue.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
/// The Id of the repository
/// The issue number
/// Options for changing the API response
public IObservable GetAllForIssue(long repositoryId, int number, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return GetAllForIssue(repositoryId, number, new IssueCommentRequest(), options);
}
///
/// Gets Issue Comments for a specified Issue.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
/// The owner of the repository
/// The name of the repository
/// The issue number
/// The sorting parameters
public IObservable GetAllForIssue(string owner, string name, int number, IssueCommentRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(request, nameof(request));
return GetAllForIssue(owner, name, number, request, ApiOptions.None);
}
///
/// Gets Issue Comments for a specified Issue.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
/// The Id of the repository
/// The issue number
/// The sorting parameters
public IObservable GetAllForIssue(long repositoryId, int number, IssueCommentRequest request)
{
Ensure.ArgumentNotNull(request, nameof(request));
return GetAllForIssue(repositoryId, number, request, ApiOptions.None);
}
///
/// Gets Issue Comments for a specified Issue.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
/// The owner of the repository
/// The name of the repository
/// The issue number
/// The sorting parameters
/// Options for changing the API response
public IObservable GetAllForIssue(string owner, string name, int number, IssueCommentRequest request, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(owner, name, number), request.ToParametersDictionary(), options);
}
///
/// Gets Issue Comments for a specified Issue.
///
/// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
/// The Id of the repository
/// The issue number
/// The sorting parameters
/// Options for changing the API response
public IObservable GetAllForIssue(long repositoryId, int number, IssueCommentRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(repositoryId, number), request.ToParametersDictionary(), options);
}
///
/// Creates a new Issue Comment for a specified Issue.
///
/// http://developer.github.com/v3/issues/comments/#create-a-comment
/// The owner of the repository
/// The name of the repository
/// The number of the issue
/// The text of the new comment
public IObservable Create(string owner, string name, int number, string newComment)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(newComment, nameof(newComment));
return _client.Create(owner, name, number, newComment).ToObservable();
}
///
/// Creates a new Issue Comment for a specified Issue.
///
/// http://developer.github.com/v3/issues/comments/#create-a-comment
/// The Id of the repository
/// The number of the issue
/// The text of the new comment
public IObservable Create(long repositoryId, int number, string newComment)
{
Ensure.ArgumentNotNull(newComment, nameof(newComment));
return _client.Create(repositoryId, number, newComment).ToObservable();
}
///
/// Updates a specified Issue Comment.
///
/// http://developer.github.com/v3/issues/comments/#edit-a-comment
/// The owner of the repository
/// The name of the repository
/// The comment id
/// The modified comment
public IObservable Update(string owner, string name, long commentId, string commentUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(commentUpdate, nameof(commentUpdate));
return _client.Update(owner, name, commentId, commentUpdate).ToObservable();
}
///
/// Updates a specified Issue Comment.
///
/// http://developer.github.com/v3/issues/comments/#edit-a-comment
/// The Id of the repository
/// The comment id
/// The modified comment
public IObservable Update(long repositoryId, long commentId, string commentUpdate)
{
Ensure.ArgumentNotNull(commentUpdate, nameof(commentUpdate));
return _client.Update(repositoryId, commentId, commentUpdate).ToObservable();
}
///
/// Deletes the specified Issue Comment
///
/// http://developer.github.com/v3/issues/comments/#delete-a-comment
/// The owner of the repository
/// The name of the repository
/// The comment id
public IObservable Delete(string owner, string name, long commentId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return _client.Delete(owner, name, commentId).ToObservable();
}
///
/// Deletes the specified Issue Comment
///
/// http://developer.github.com/v3/issues/comments/#delete-a-comment
/// The Id of the repository
/// The comment id
public IObservable Delete(long repositoryId, long commentId)
{
return _client.Delete(repositoryId, commentId).ToObservable();
}
}
}