Files
octokit.net/Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs
2016-09-15 02:15:11 +02:00

251 lines
11 KiB
C#

using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Issue Comments API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/issues/comments/">Issue Comments API documentation</a> for more information.
/// </remarks>
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;
}
/// <summary>
/// Gets a single Issue Comment by id.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#get-a-single-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="id">The issue comment id</param>
public IObservable<IssueComment> Get(string owner, string name, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Get(owner, name, id).ToObservable();
}
/// <summary>
/// Gets a single Issue Comment by id.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#get-a-single-comment</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="id">The issue comment id</param>
public IObservable<IssueComment> Get(long repositoryId, int id)
{
return _client.Get(repositoryId, id).ToObservable();
}
/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
public IObservable<IssueComment> GetAllForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAllForRepository(owner, name, ApiOptions.None);
}
/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="repositoryId">The Id of the repository</param>
public IObservable<IssueComment> GetAllForRepository(long repositoryId)
{
return GetAllForRepository(repositoryId, ApiOptions.None);
}
/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="options">Options for changing the API response</param>
public IObservable<IssueComment> GetAllForRepository(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<IssueComment>(ApiUrls.IssueComments(owner, name), null, AcceptHeaders.ReactionsPreview, options);
}
/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="options">Options for changing the API response</param>
public IObservable<IssueComment> GetAllForRepository(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<IssueComment>(ApiUrls.IssueComments(repositoryId), options);
}
/// <summary>
/// Gets Issue Comments for a specified Issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The issue number</param>
public IObservable<IssueComment> GetAllForIssue(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAllForIssue(owner, name, number, ApiOptions.None);
}
/// <summary>
/// Gets Issue Comments for a specified Issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The issue number</param>
public IObservable<IssueComment> GetAllForIssue(long repositoryId, int number)
{
return GetAllForIssue(repositoryId, number, ApiOptions.None);
}
/// <summary>
/// Gets Issue Comments for a specified Issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The issue number</param>
/// <param name="options">Options for changing the API response</param>
public IObservable<IssueComment> GetAllForIssue(string owner, string name, int number, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<IssueComment>(ApiUrls.IssueComments(owner, name, number), null, AcceptHeaders.ReactionsPreview, options);
}
/// <summary>
/// Gets Issue Comments for a specified Issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The issue number</param>
/// <param name="options">Options for changing the API response</param>
public IObservable<IssueComment> GetAllForIssue(long repositoryId, int number, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<IssueComment>(ApiUrls.IssueComments(repositoryId, number), options);
}
/// <summary>
/// Creates a new Issue Comment for a specified Issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#create-a-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The number of the issue</param>
/// <param name="newComment">The text of the new comment</param>
public IObservable<IssueComment> 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();
}
/// <summary>
/// Creates a new Issue Comment for a specified Issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#create-a-comment</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The number of the issue</param>
/// <param name="newComment">The text of the new comment</param>
public IObservable<IssueComment> Create(long repositoryId, int number, string newComment)
{
Ensure.ArgumentNotNull(newComment, "newComment");
return _client.Create(repositoryId, number, newComment).ToObservable();
}
/// <summary>
/// Updates a specified Issue Comment.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#edit-a-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="id">The comment id</param>
/// <param name="commentUpdate">The modified comment</param>
public IObservable<IssueComment> 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();
}
/// <summary>
/// Updates a specified Issue Comment.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#edit-a-comment</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="id">The comment id</param>
/// <param name="commentUpdate">The modified comment</param>
public IObservable<IssueComment> Update(long repositoryId, int id, string commentUpdate)
{
Ensure.ArgumentNotNull(commentUpdate, "commentUpdate");
return _client.Update(repositoryId, id, commentUpdate).ToObservable();
}
/// <summary>
/// Deletes the specified Issue Comment
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#delete-a-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="id">The comment id</param>
public IObservable<Unit> Delete(string owner, string name, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Delete(owner, name, id).ToObservable();
}
/// <summary>
/// Deletes the specified Issue Comment
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#delete-a-comment</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="id">The comment id</param>
public IObservable<Unit> Delete(long repositoryId, int id)
{
return _client.Delete(repositoryId, id).ToObservable();
}
}
}