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, "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, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Get(owner, name, id).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(int repositoryId, int id)
{
return _client.Get(repositoryId, id).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, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "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(int 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, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(owner, name), null, AcceptHeaders.ReactionsPreview, 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(int repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(repositoryId), 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, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "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(int 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, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(owner, name, number), null, AcceptHeaders.ReactionsPreview, 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(int repositoryId, int number, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(repositoryId, number), 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, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(newComment, "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(int repositoryId, int number, string newComment)
{
Ensure.ArgumentNotNull(newComment, "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, int id, string commentUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(commentUpdate, "commentUpdate");
return _client.Update(owner, name, id, 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(int repositoryId, int id, string commentUpdate)
{
Ensure.ArgumentNotNull(commentUpdate, "commentUpdate");
return _client.Update(repositoryId, id, 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, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Delete(owner, name, id).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(int repositoryId, int id)
{
return _client.Delete(repositoryId, id).ToObservable();
}
}
}