using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
public class ObservableRepositoryCommentsClient : IObservableRepositoryCommentsClient
{
readonly IRepositoryCommentsClient _client;
readonly IConnection _connection;
public ObservableRepositoryCommentsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.Repository.Comment;
_connection = client.Connection;
}
///
/// Gets a single Repository Comment by number.
///
/// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment
/// The owner of the repository
/// The name of the repository
/// The comment id
///
public IObservable Get(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Get(owner, name, number).ToObservable();
}
///
/// Gets Commit Comments for a repository.
///
/// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-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 _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name));
}
///
/// Gets Commit Comments for a specified Commit.
///
/// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit
/// The owner of the repository
/// The name of the repository
/// The sha of the commit
///
public IObservable GetAllForCommit(string owner, string name, string sha)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(sha, "sha");
return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name, sha));
}
///
/// Creates a new Commit Comment for a specified Commit.
///
/// http://developer.github.com/v3/repos/comments/#create-a-commit-comment
/// The owner of the repository
/// The name of the repository
/// The sha reference of commit
/// The new comment to add to the commit
///
public IObservable Create(string owner, string name, string sha, NewCommitComment newCommitComment)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(sha, "sha");
Ensure.ArgumentNotNull(newCommitComment, "newCommitComment");
return _client.Create(owner, name, sha, newCommitComment).ToObservable();
}
///
/// Updates a specified Commit Comment.
///
/// http://developer.github.com/v3/repos/comments/#update-a-commit-comment
/// The owner of the repository
/// The name of the repository
/// The comment number
/// The modified comment
///
public IObservable Update(string owner, string name, int number, string commentUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(commentUpdate, "commentUpdate");
return _client.Update(owner, name, number, commentUpdate).ToObservable();
}
///
/// Deletes the specified Commit Comment
///
/// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment
/// The owner of the repository
/// The name of the repository
/// The comment id
///
public IObservable Delete(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Delete(owner, name, number).ToObservable();
}
}
}