Add and implement IObservableMilestonesClient

This commit is contained in:
Keith Dahlby
2013-10-30 23:03:54 -05:00
parent 5baaa171d6
commit 9b5b00ba20
3 changed files with 206 additions and 0 deletions
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reactive;
namespace Octokit
{
public interface IObservableMilestonesClient
{
/// <summary>
/// Gets a single Milestone by number.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/issues/milestones/#get-a-single-milestone
/// </remarks>
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
Justification = "Method makes a network request")]
IObservable<Milestone> Get(string owner, string name, int number);
/// <summary>
/// Gets all open milestones for the repository.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
IObservable<Milestone> GetForRepository(string owner, string name);
/// <summary>
/// Gets all open milestones for the repository.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">Used to filter and sort the list of Milestones returned</param>
/// <returns></returns>
IObservable<Milestone> GetForRepository(string owner, string name, MilestoneRequest request);
/// <summary>
/// Creates a milestone for the specified repository. Any user with pull access to a repository can create an
/// Milestone.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/milestones/#create-a-milestone</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="newMilestone">A <see cref="NewMilestone"/> instance describing the new Milestone to create</param>
/// <returns></returns>
IObservable<Milestone> Create(string owner, string name, NewMilestone newMilestone);
/// <summary>
/// Creates a milestone for the specified repository. Any user with pull access to a repository can create an
/// Milestone.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/milestones/#update-a-milestone</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The Milestone number</param>
/// <param name="milestoneUpdate">An <see cref="MilestoneUpdate"/> instance describing the changes to make to the Milestone
/// </param>
/// <returns></returns>
IObservable<Milestone> Update(string owner, string name, int number, MilestoneUpdate milestoneUpdate);
/// <summary>
/// Deletes a milestone for the specified repository. Any user with pull access to a repository can create an
/// Milestone.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/milestones/#delete-a-milestone</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The milestone number</param>
/// <returns></returns>
IObservable<Unit> Delete(string owner, string name, int number);
}
}
@@ -0,0 +1,125 @@
using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive.Clients
{
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;
}
/// <summary>
/// Gets a single Milestone by number.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/issues/milestones/#get-a-single-milestone
/// </remarks>
/// <returns></returns>
public IObservable<Milestone> Get(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Get(owner, name, number).ToObservable();
}
/// <summary>
/// Gets all open milestones for the repository.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public IObservable<Milestone> GetForRepository(string owner, string name)
{
return _connection.GetAndFlattenAllPages<Milestone>(ApiUrls.Milestones(owner, name));
}
/// <summary>
/// Gets all open milestones for the repository.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">Used to filter and sort the list of Milestones returned</param>
/// <returns></returns>
public IObservable<Milestone> GetForRepository(string owner, string name, MilestoneRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(request, "request");
return _connection.GetAndFlattenAllPages<Milestone>(ApiUrls.Milestones(owner, name),
request.ToParametersDictionary());
}
/// <summary>
/// Creates an Milestone for the specified repository. Any user with pull access to a repository can create an
/// Milestone.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/milestones/#create-a-milestone</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="newMilestone">A <see cref="NewMilestone"/> instance describing the new Milestone to create</param>
/// <returns></returns>
public IObservable<Milestone> 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();
}
/// <summary>
/// Creates an Milestone for the specified repository. Any user with pull access to a repository can create an
/// Milestone.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/milestones/#create-a-milestone</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The Milestone number</param>
/// <param name="milestoneUpdate">An <see cref="MilestoneUpdate"/> instance describing the changes to make to the Milestone
/// </param>
/// <returns></returns>
public IObservable<Milestone> 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();
}
/// <summary>
/// Deletes a milestone for the specified repository. Any user with pull access to a repository can create an
/// Milestone.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/milestones/#delete-a-milestone</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The milestone number</param>
/// <returns></returns>
public IObservable<Unit> Delete(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Delete(owner, name, number).ToObservable();
}
}
}
+2
View File
@@ -71,6 +71,8 @@
<Compile Include="..\SolutionInfo.cs">
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="Clients\IObservableMilestonesClient.cs" />
<Compile Include="Clients\ObservableMilestonesClient.cs" />
<Compile Include="Clients\ObservableAssigneesClient.cs" />
<Compile Include="Clients\IObservableCommitStatusClient.cs" />
<Compile Include="Clients\ObservableCommitStatusClient.cs" />