using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
public class ObservableGistCommentsClient : IObservableGistCommentsClient
{
readonly IGistCommentsClient _client;
readonly IConnection _connection;
public ObservableGistCommentsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));
_client = client.Gist.Comment;
_connection = client.Connection;
}
///
/// Gets a single comment by gist- and comment id.
///
/// http://developer.github.com/v3/gists/comments/#get-a-single-comment
/// The id of the gist
/// The id of the comment
/// IObservable{GistComment}.
public IObservable Get(string gistId, long commentId)
{
return _client.Get(gistId, commentId).ToObservable();
}
///
/// Gets all comments for the gist with the specified id.
///
/// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist
/// The id of the gist
/// IObservable{GistComment}.
public IObservable GetAllForGist(string gistId)
{
Ensure.ArgumentNotNullOrEmptyString(gistId, nameof(gistId));
return GetAllForGist(gistId, ApiOptions.None);
}
///
/// Gets all comments for the gist with the specified id.
///
/// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist
/// The id of the gist
/// Options for changing the API response
/// IObservable{GistComment}.
public IObservable GetAllForGist(string gistId, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(gistId, nameof(gistId));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.GistComments(gistId), options);
}
///
/// Creates a comment for the gist with the specified id.
///
/// http://developer.github.com/v3/gists/comments/#create-a-comment
/// The id of the gist
/// The body of the comment
/// IObservable{GistComment}.
public IObservable Create(string gistId, string comment)
{
Ensure.ArgumentNotNullOrEmptyString(comment, nameof(comment));
return _client.Create(gistId, comment).ToObservable();
}
///
/// Updates the comment with the specified gist- and comment id.
///
/// http://developer.github.com/v3/gists/comments/#edit-a-comment
/// The id of the gist
/// The id of the comment
/// The updated body of the comment
/// IObservable{GistComment}.
public IObservable Update(string gistId, long commentId, string comment)
{
Ensure.ArgumentNotNullOrEmptyString(comment, nameof(comment));
return _client.Update(gistId, commentId, comment).ToObservable();
}
///
/// Deletes the comment with the specified gist- and comment id.
///
/// http://developer.github.com/v3/gists/comments/#delete-a-comment
/// The id of the gist
/// The id of the comment
/// IObservable{Unit}.
public IObservable Delete(string gistId, long commentId)
{
return _client.Delete(gistId, commentId).ToObservable();
}
}
}