using System; using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { /// /// A client for GitHub's Issue Milestones API. /// /// /// See the Issue Milestones API documentation for more information. /// public class ObservableMilestonesClient : IObservableMilestonesClient { readonly IMilestonesClient _client; readonly IConnection _connection; public ObservableMilestonesClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _client = client.Issue.Milestone; _connection = client.Connection; } /// /// Gets a single Milestone by number. /// /// /// http://developer.github.com/v3/issues/milestones/#get-a-single-milestone /// /// 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 a single Milestone by number. /// /// /// http://developer.github.com/v3/issues/milestones/#get-a-single-milestone /// /// public IObservable Get(int repositoryId, int number) { return _client.Get(repositoryId, number).ToObservable(); } /// /// Gets all open milestones for the repository. /// /// /// http://developer.github.com/v3/issues/milestones/#list-milestones-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 GetAllForRepository(owner, name, ApiOptions.None); } /// /// Gets all open milestones for the repository. /// /// /// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository /// /// The ID of the repository /// public IObservable GetAllForRepository(int repositoryId) { return GetAllForRepository(repositoryId, ApiOptions.None); } /// /// Gets all open milestones for the repository. /// /// /// http://developer.github.com/v3/issues/milestones/#list-milestones-for-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.Milestones(owner, name), options); } /// /// Gets all open milestones for the repository. /// /// /// http://developer.github.com/v3/issues/milestones/#list-milestones-for-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.Milestones(repositoryId), options); } /// /// Gets all open milestones for the repository. /// /// /// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository /// /// The owner of the repository /// The name of the repository /// Used to filter and sort the list of Milestones returned /// public IObservable GetAllForRepository(string owner, string name, MilestoneRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); return GetAllForRepository(owner, name, request, ApiOptions.None); } /// /// Gets all open milestones for the repository. /// /// /// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository /// /// The ID of the repository /// Used to filter and sort the list of Milestones returned /// public IObservable GetAllForRepository(int repositoryId, MilestoneRequest request) { Ensure.ArgumentNotNull(request, "request"); return GetAllForRepository(repositoryId, request, ApiOptions.None); } /// /// Gets all open milestones for the repository. /// /// /// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository /// /// The owner of the repository /// The name of the repository /// Used to filter and sort the list of Milestones returned /// Options for changing the API response /// public IObservable GetAllForRepository(string owner, string name, MilestoneRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.Milestones(owner, name), request.ToParametersDictionary(), options); } /// /// Gets all open milestones for the repository. /// /// /// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository /// /// The ID of the repository /// Used to filter and sort the list of Milestones returned /// Options for changing the API response /// public IObservable GetAllForRepository(int repositoryId, MilestoneRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.Milestones(repositoryId), request.ToParametersDictionary(), options); } /// /// Creates a milestone for the specified repository. Any user with pull access to a repository can create a /// Milestone. /// /// http://developer.github.com/v3/issues/milestones/#create-a-milestone /// The owner of the repository /// The name of the repository /// A instance describing the new Milestone to create /// public IObservable Create(string owner, string name, NewMilestone newMilestone) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(newMilestone, "newMilestone"); return _client.Create(owner, name, newMilestone).ToObservable(); } /// /// Creates a milestone for the specified repository. Any user with pull access to a repository can create a /// Milestone. /// /// http://developer.github.com/v3/issues/milestones/#create-a-milestone /// The ID of the repository /// A instance describing the new Milestone to create /// public IObservable Create(int repositoryId, NewMilestone newMilestone) { Ensure.ArgumentNotNull(newMilestone, "newMilestone"); return _client.Create(repositoryId, newMilestone).ToObservable(); } /// /// Updates a milestone for the specified repository. Any user with pull access to a repository can create a /// Milestone. /// /// http://developer.github.com/v3/issues/milestones/#update-a-milestone /// The owner of the repository /// The name of the repository /// The Milestone number /// An instance describing the changes to make to the Milestone /// /// public IObservable Update(string owner, string name, int number, MilestoneUpdate milestoneUpdate) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(milestoneUpdate, "milestoneUpdate"); return _client.Update(owner, name, number, milestoneUpdate).ToObservable(); } /// /// Updates a milestone for the specified repository. Any user with pull access to a repository can create a /// Milestone. /// /// http://developer.github.com/v3/issues/milestones/#update-a-milestone /// The ID of the repository /// The Milestone number /// An instance describing the changes to make to the Milestone /// /// public IObservable Update(int repositoryId, int number, MilestoneUpdate milestoneUpdate) { Ensure.ArgumentNotNull(milestoneUpdate, "milestoneUpdate"); return _client.Update(repositoryId, number, milestoneUpdate).ToObservable(); } /// /// Deletes a milestone for the specified repository. Any user with pull access to a repository can create an /// Milestone. /// /// http://developer.github.com/v3/issues/milestones/#delete-a-milestone /// The owner of the repository /// The name of the repository /// The milestone number /// public IObservable Delete(string owner, string name, int number) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _client.Delete(owner, name, number).ToObservable(); } /// /// Deletes a milestone for the specified repository. Any user with pull access to a repository can create an /// Milestone. /// /// http://developer.github.com/v3/issues/milestones/#delete-a-milestone /// The ID of the repository /// The milestone number /// public IObservable Delete(int repositoryId, int number) { return _client.Delete(repositoryId, number).ToObservable(); } } }