Added reactive client

This commit is contained in:
Kristian Hellang
2013-11-25 00:57:45 +01:00
parent ca40a397d2
commit db7624a4ba
8 changed files with 230 additions and 0 deletions

View File

@@ -7,5 +7,6 @@
{ {
IObservableTagsClient Tag { get; set; } IObservableTagsClient Tag { get; set; }
IObservableCommitsClient Commit { get; set; } IObservableCommitsClient Commit { get; set; }
IObservableReferencesClient Reference { get; set; }
} }
} }

View File

@@ -0,0 +1,83 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive;
namespace Octokit.Reactive
{
public interface IObservableReferencesClient
{
/// <summary>
/// Gets a reference for a given repository by reference name
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-a-reference
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">Tha name of the reference</param>
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
Justification = "Method makes a network request")]
IObservable<Reference> Get(string owner, string name, string reference);
/// <summary>
/// Gets all references for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
IObservable<Reference> GetAll(string owner, string name);
/// <summary>
/// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads"
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="subNamespace">The sub-namespace to get references for</param>
/// <returns></returns>
IObservable<Reference> GetAll(string owner, string name, string subNamespace);
/// <summary>
/// Creates a reference for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#create-a-reference
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The reference to create</param>
/// <returns></returns>
IObservable<Reference> Create(string owner, string name, NewReference reference);
/// <summary>
/// Updates a reference for a given repository by reference name
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#update-a-reference
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The name of the reference</param>
/// <param name="referenceUpdate">The updated reference data</param>
/// <returns></returns>
IObservable<Reference> Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate);
/// <summary>
/// Deletes a reference for a given repository by reference name
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#delete-a-reference
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The name of the reference</param>
/// <returns></returns>
IObservable<Unit> Delete(string owner, string name, string reference);
}
}

View File

@@ -6,9 +6,11 @@
{ {
Tag = new ObservableTagsClient(client); Tag = new ObservableTagsClient(client);
Commit = new ObservableCommitsClient(client); Commit = new ObservableCommitsClient(client);
Reference = new ObservableReferencesClient(client);
} }
public IObservableTagsClient Tag { get; set; } public IObservableTagsClient Tag { get; set; }
public IObservableCommitsClient Commit { get; set; } public IObservableCommitsClient Commit { get; set; }
public IObservableReferencesClient Reference { get; set; }
} }
} }

View File

@@ -0,0 +1,136 @@
using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
public class ObservableReferencesClient : IObservableReferencesClient
{
readonly IReferencesClient _reference;
readonly IConnection _connection;
public ObservableReferencesClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_reference = client.GitDatabase.Reference;
_connection = client.Connection;
}
/// <summary>
/// Gets a reference for a given repository by reference name
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-a-reference
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">Tha name of the reference</param>
/// <returns></returns>
public IObservable<Reference> Get(string owner, string name, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return _reference.Get(owner, name, reference).ToObservable();
}
/// <summary>
/// Gets all references for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public IObservable<Reference> GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _connection.GetAndFlattenAllPages<Reference>(ApiUrls.Reference(owner, name));
}
/// <summary>
/// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads"
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="subNamespace">The sub-namespace to get references for</param>
/// <returns></returns>
public IObservable<Reference> GetAll(string owner, string name, string subNamespace)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(subNamespace, "subNamespace");
return _connection.GetAndFlattenAllPages<Reference>(ApiUrls.Reference(owner, name, subNamespace));
}
/// <summary>
/// Creates a reference for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#create-a-reference
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The reference to create</param>
/// <returns></returns>
public IObservable<Reference> Create(string owner, string name, NewReference reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(reference, "reference");
return _reference.Create(owner, name, reference).ToObservable();
}
/// <summary>
/// Updates a reference for a given repository by reference name
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#update-a-reference
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The name of the reference</param>
/// <param name="referenceUpdate">The updated reference data</param>
/// <returns></returns>
public IObservable<Reference> Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
Ensure.ArgumentNotNull(referenceUpdate, "update");
return _reference.Update(owner, name, reference, referenceUpdate).ToObservable();
}
/// <summary>
/// Deletes a reference for a given repository by reference name
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#delete-a-reference
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The name of the reference</param>
/// <returns></returns>
public IObservable<Unit> Delete(string owner, string name, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return _reference.Delete(owner, name, reference).ToObservable();
}
}
}

View File

@@ -110,6 +110,8 @@
<Compile Include="Clients\ObservableBlobClient.cs" /> <Compile Include="Clients\ObservableBlobClient.cs" />
<Compile Include="Clients\IObservableStarredClient.cs" /> <Compile Include="Clients\IObservableStarredClient.cs" />
<Compile Include="Clients\ObservableStarredClient.cs" /> <Compile Include="Clients\ObservableStarredClient.cs" />
<Compile Include="Clients\IObservableReferencesClient.cs" />
<Compile Include="Clients\ObservableReferencesClient.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>

View File

@@ -119,6 +119,8 @@
<Compile Include="Clients\ObservableBlobClient.cs" /> <Compile Include="Clients\ObservableBlobClient.cs" />
<Compile Include="Clients\IObservableStarredClient.cs" /> <Compile Include="Clients\IObservableStarredClient.cs" />
<Compile Include="Clients\ObservableStarredClient.cs" /> <Compile Include="Clients\ObservableStarredClient.cs" />
<Compile Include="Clients\IObservableReferencesClient.cs" />
<Compile Include="Clients\ObservableReferencesClient.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<ItemGroup> <ItemGroup>

View File

@@ -114,6 +114,8 @@
<Compile Include="Clients\ObservableBlobClient.cs" /> <Compile Include="Clients\ObservableBlobClient.cs" />
<Compile Include="Clients\IObservableStarredClient.cs" /> <Compile Include="Clients\IObservableStarredClient.cs" />
<Compile Include="Clients\ObservableStarredClient.cs" /> <Compile Include="Clients\ObservableStarredClient.cs" />
<Compile Include="Clients\IObservableReferencesClient.cs" />
<Compile Include="Clients\ObservableReferencesClient.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>

View File

@@ -74,6 +74,8 @@
<Link>Properties\SolutionInfo.cs</Link> <Link>Properties\SolutionInfo.cs</Link>
</Compile> </Compile>
<Compile Include="Clients\IObservableBlobClient.cs" /> <Compile Include="Clients\IObservableBlobClient.cs" />
<Compile Include="Clients\IObservableReferencesClient.cs" />
<Compile Include="Clients\ObservableReferencesClient.cs" />
<Compile Include="Clients\ObservableRepoCollaboratorsClient.cs" /> <Compile Include="Clients\ObservableRepoCollaboratorsClient.cs" />
<Compile Include="Clients\IObservableRepoCollaboratorsClient.cs" /> <Compile Include="Clients\IObservableRepoCollaboratorsClient.cs" />
<Compile Include="Clients\ObservableOrganizationTeamsClient.cs" /> <Compile Include="Clients\ObservableOrganizationTeamsClient.cs" />