mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 11:05:56 +00:00
implementation for reactive repo collab client
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
using Octokit.Reactive.Internal;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
public class ObservableRepoCollaboratorsClient : IObservableRepoCollaboratorsClient
|
||||
{
|
||||
readonly IRepoCollaboratorsClient _client;
|
||||
readonly IConnection _connection;
|
||||
|
||||
public ObservableRepoCollaboratorsClient(IGitHubClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
_client = client.Repository.RepoCollaborators;
|
||||
_connection = client.Connection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the available collaborators on this repo.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<User> GetAll(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNull(owner, "owner");
|
||||
Ensure.ArgumentNotNull(name, "name");
|
||||
var endpoint = ApiUrls.RepoCollaborators(owner, name);
|
||||
return _connection.GetAndFlattenAllPages<User>(endpoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if a user is an assignee for a repository.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="user">Username of the prospective collaborator</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<bool> IsCollaborator(string owner, string name, string user)
|
||||
{
|
||||
return _client.IsCollaborator(owner, name, user).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a user as a collaborator to a repository.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="user">Username of the prospective collaborator</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<Unit> Add(string owner, string name, string user)
|
||||
{
|
||||
return _client.Add(owner, name, user).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a user as a collaborator for a repository.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="user">Username of the prospective collaborator</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<Unit> Delete(string owner, string name, string user)
|
||||
{
|
||||
return _client.Delete(owner, name, user).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,8 @@
|
||||
<Compile Include="..\SolutionInfo.cs">
|
||||
<Link>Properties\SolutionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Clients\ObservableRepoCollaboratorsClient.cs" />
|
||||
<Compile Include="Clients\IObservableRepoCollaboratorsClient.cs" />
|
||||
<Compile Include="Clients\ObservableOrganizationTeamsClient.cs" />
|
||||
<Compile Include="Clients\IObservableOrganizationTeamsClient.cs" />
|
||||
<Compile Include="Clients\IObservableCommitsClient.cs" />
|
||||
|
||||
@@ -37,8 +37,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
|
||||
|
||||
var endpoint = "repos/{0}/{1}/collaborators".FormatUri(owner, repo);
|
||||
|
||||
var endpoint = ApiUrls.RepoCollaborators(owner, repo);
|
||||
return ApiConnection.GetAll<User>(endpoint);
|
||||
}
|
||||
|
||||
|
||||
@@ -570,5 +570,17 @@ namespace Octokit
|
||||
{
|
||||
return "teams/{0}".FormatUri(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns the <see cref="Uri"/> for teams
|
||||
/// use for update or deleting a team
|
||||
/// </summary>
|
||||
/// <param name="owner">owner of repo</param>
|
||||
/// /// <param name="repo">name of repo</param>
|
||||
/// <returns></returns>
|
||||
public static Uri RepoCollaborators(string owner, string repo)
|
||||
{
|
||||
return "repos/{0}/{1}/collaborators".FormatUri(owner, repo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user