using System; using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { public class ObservableGistsClient : IObservableGistsClient { readonly IGistsClient _client; readonly IConnection _connection; public ObservableGistsClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _client = client.Gist; _connection = client.Connection; Comment = new ObservableGistCommentsClient(client); } public IObservableGistCommentsClient Comment { get; set; } /// /// Gets a gist /// /// /// http://developer.github.com/v3/gists/#get-a-single-gist /// /// The id of the gist public IObservable Get(string id) { Ensure.ArgumentNotNullOrEmptyString(id, "id"); return _client.Get(id).ToObservable(); } /// /// Creates a new gist /// /// /// http://developer.github.com/v3/gists/#create-a-gist /// /// The new gist to create public IObservable Create(NewGist newGist) { Ensure.ArgumentNotNull(newGist, "newGist"); return _client.Create(newGist).ToObservable(); } /// /// Creates a fork of a gist /// /// /// http://developer.github.com/v3/gists/#fork-a-gist /// /// The id of the gist to fork public IObservable Fork(string id) { return _client.Fork(id).ToObservable(); } /// /// Deletes a gist /// /// /// http://developer.github.com/v3/gists/#delete-a-gist /// /// The id of the gist public IObservable Delete(string id) { Ensure.ArgumentNotNull(id, "id"); return _client.Delete(id).ToObservable(); } /// /// List the authenticated user’s gists or if called anonymously, /// this will return all public gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// public IObservable GetAll() { return GetAll(ApiOptions.None); } /// /// List the authenticated user’s gists or if called anonymously, /// this will return all public gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// /// Options for changing the API response public IObservable GetAll(ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.Gist(), options); } /// /// List the authenticated user’s gists or if called anonymously, /// this will return all public gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// /// Only gists updated at or after this time are returned public IObservable GetAll(DateTimeOffset since) { return GetAll(since, ApiOptions.None); } /// /// List the authenticated user’s gists or if called anonymously, /// this will return all public gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// /// Only gists updated at or after this time are returned /// Options for changing the API response public IObservable GetAll(DateTimeOffset since, ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); var request = new GistRequest(since); return _connection.GetAndFlattenAllPages(ApiUrls.Gist(), request.ToParametersDictionary(), options); } /// /// Lists all public gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// public IObservable GetAllPublic() { return GetAllPublic(ApiOptions.None); } /// /// Lists all public gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// /// Options for changing the API response public IObservable GetAllPublic(ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.PublicGists(), options); } /// /// Lists all public gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// /// Only gists updated at or after this time are returned public IObservable GetAllPublic(DateTimeOffset since) { return GetAllPublic(since, ApiOptions.None); } /// /// Lists all public gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// /// Only gists updated at or after this time are returned /// Options for changing the API response public IObservable GetAllPublic(DateTimeOffset since, ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); var request = new GistRequest(since); return _connection.GetAndFlattenAllPages(ApiUrls.PublicGists(), request.ToParametersDictionary(), options); } /// /// List the authenticated user’s starred gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// public IObservable GetAllStarred() { return GetAllStarred(ApiOptions.None); } /// /// List the authenticated user’s starred gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// /// Options for changing the API response public IObservable GetAllStarred(ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.StarredGists(), options); } /// /// List the authenticated user’s starred gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// /// Only gists updated at or after this time are returned public IObservable GetAllStarred(DateTimeOffset since) { return GetAllStarred(since, ApiOptions.None); } /// /// List the authenticated user’s starred gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// /// Only gists updated at or after this time are returned /// Options for changing the API response public IObservable GetAllStarred(DateTimeOffset since, ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); var request = new GistRequest(since); return _connection.GetAndFlattenAllPages(ApiUrls.StarredGists(), request.ToParametersDictionary(), options); } /// /// List a user's gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// /// The user public IObservable GetAllForUser(string user) { Ensure.ArgumentNotNullOrEmptyString(user, "user"); return GetAllForUser(user, ApiOptions.None); } /// /// List a user's gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// /// The user /// Options for changing the API response public IObservable GetAllForUser(string user, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.UsersGists(user), options); } /// /// List a user's gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// /// The user /// Only gists updated at or after this time are returned public IObservable GetAllForUser(string user, DateTimeOffset since) { Ensure.ArgumentNotNullOrEmptyString(user, "user"); return GetAllForUser(user, since, ApiOptions.None); } /// /// List a user's gists /// /// /// http://developer.github.com/v3/gists/#list-gists /// /// The user /// Only gists updated at or after this time are returned /// Options for changing the API response public IObservable GetAllForUser(string user, DateTimeOffset since, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNull(options, "options"); var request = new GistRequest(since); return _connection.GetAndFlattenAllPages(ApiUrls.UsersGists(user), request.ToParametersDictionary(), options); } /// /// List gist commits /// /// /// http://developer.github.com/v3/gists/#list-gists-commits /// /// The id of the gist public IObservable GetAllCommits(string id) { Ensure.ArgumentNotNullOrEmptyString(id, "id"); return GetAllCommits(id, ApiOptions.None); } /// /// List gist commits /// /// /// http://developer.github.com/v3/gists/#list-gists-commits /// /// The id of the gist /// Options for changing the API response public IObservable GetAllCommits(string id, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(id, "id"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.GistCommits(id), options); } /// /// List gist forks /// /// /// http://developer.github.com/v3/gists/#list-gists-forks /// /// The id of the gist public IObservable GetAllForks(string id) { Ensure.ArgumentNotNullOrEmptyString(id, "id"); return GetAllForks(id, ApiOptions.None); } /// /// List gist forks /// /// /// http://developer.github.com/v3/gists/#list-gists-forks /// /// The id of the gist /// Options for changing the API response public IObservable GetAllForks(string id, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(id, "id"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.ForkGist(id), options); } /// /// Edits a gist /// /// /// http://developer.github.com/v3/gists/#delete-a-gist /// /// The id of the gist /// The update to the gist public IObservable Edit(string id, GistUpdate gistUpdate) { Ensure.ArgumentNotNull(id, "id"); Ensure.ArgumentNotNull(gistUpdate, "gistUpdate"); return _client.Edit(id, gistUpdate).ToObservable(); } /// /// Stars a gist /// /// /// http://developer.github.com/v3/gists/#star-a-gist /// /// The id of the gist public IObservable Star(string id) { return _client.Star(id).ToObservable(); } /// /// Unstars a gist /// /// /// http://developer.github.com/v3/gists/#unstar-a-gist /// /// The id of the gist public IObservable Unstar(string id) { return _client.Unstar(id).ToObservable(); } /// /// Checks if the gist is starred /// /// /// http://developer.github.com/v3/gists/#check-if-a-gist-is-starred /// /// The id of the gist public IObservable IsStarred(string id) { Ensure.ArgumentNotNullOrEmptyString(id, "id"); return _client.IsStarred(id).ToObservable(); } } }