using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
///
/// A client for GitHub's Org Teams API.
///
///
/// See the Orgs API documentation for more information.
///
public class ObservableTeamsClient : IObservableTeamsClient
{
readonly IConnection _connection;
readonly ITeamsClient _client;
///
/// Initializes a new Organization Teams API client.
///
/// An used to make the requests
public ObservableTeamsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_connection = client.Connection;
_client = client.Organization.Team;
}
///
/// Gets a single by identifier.
///
///
/// https://developer.github.com/v3/orgs/teams/#get-team
///
/// The team identifier.
/// The with the given identifier.
public IObservable Get(int id)
{
return _client.Get(id).ToObservable();
}
///
/// Returns all s for the current org.
///
/// Thrown when a general API error occurs.
/// A list of the orgs's teams s.
public IObservable GetAll(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");
return GetAll(org, ApiOptions.None);
}
///
/// Returns all s for the current org.
///
/// Organization to list all teams of.
/// Options to change API behaviour.
/// Thrown when a general API error occurs.
/// A list of the orgs's teams s.
public IObservable GetAll(string org, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationTeams(org), options);
}
///
/// Returns all s for the current user.
///
/// Thrown when a general API error occurs.
/// A list of the user's s.
public IObservable GetAllForCurrent()
{
return GetAllForCurrent(ApiOptions.None);
}
///
/// Returns all s for the current user.
///
/// Options to change API behaviour.
/// Thrown when a general API error occurs.
/// A list of the user's s.
public IObservable GetAllForCurrent(ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.UserTeams(), options);
}
///
/// Returns all members of the given team.
///
/// The team identifier
///
/// https://developer.github.com/v3/orgs/teams/#list-team-members
///
/// Thrown when a general API error occurs.
/// A list of the team's member s.
public IObservable GetAllMembers(int id)
{
return GetAllMembers(id, ApiOptions.None);
}
///
/// Returns all members of the given team.
///
///
/// https://developer.github.com/v3/orgs/teams/#list-team-members
///
/// The team identifier
/// Options to change API behaviour.
/// Thrown when a general API error occurs.
/// A list of the team's member s.
public IObservable GetAllMembers(int id, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.TeamMembers(id), options);
}
///
/// Returns newly created for the current org.
///
/// Thrown when a general API error occurs.
/// Newly created
public IObservable Create(string org, NewTeam team)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");
Ensure.ArgumentNotNull(team, "team");
return _client.Create(org, team).ToObservable();
}
///
/// Returns updated for the current org.
///
/// Thrown when a general API error occurs.
/// Updated
public IObservable Update(int id, UpdateTeam team)
{
Ensure.ArgumentNotNull(team, "team");
return _client.Update(id, team).ToObservable();
}
///
/// Delete a team - must have owner permissions to this
///
/// Thrown when a general API error occurs.
///
public IObservable Delete(int id)
{
return _client.Delete(id).ToObservable();
}
///
/// Adds a to a .
///
///
/// See the API documentation for more information.
///
/// The team identifier.
/// The user to add to the team.
/// Thrown if you attempt to add an organization to a team.
/// A result indicating the membership status
public IObservable AddMembership(int id, string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
return _client.AddMembership(id, login).ToObservable();
}
///
/// Removes a from a .
///
///
/// See the API documentation for more information.
///
/// The team identifier.
/// The user to remove from the team.
/// if the user was removed from the team; otherwise.
public IObservable RemoveMembership(int id, string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
return _client.RemoveMembership(id, login).ToObservable();
}
///
/// Gets whether the user with the given
/// is a member of the team with the given .
///
/// The team to check.
/// The user to check.
/// A result indicating the membership status
public IObservable GetMembership(int id, string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
return _client.GetMembership(id, login).ToObservable();
}
///
/// Returns all team's repositories.
///
/// Thrown when a general API error occurs.
/// The team's repositories
public IObservable GetAllRepositories(int id)
{
return GetAllRepositories(id, ApiOptions.None);
}
///
/// Returns all team's repositories.
///
/// Team Id.
/// Options to change API behaviour.
/// Thrown when a general API error occurs.
/// The team's repositories
public IObservable GetAllRepositories(int id, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.TeamRepositories(id), null, AcceptHeaders.OrganizationPermissionsPreview, options);
}
///
/// Adds a to a .
///
/// The team identifier.
/// Org to associate the repo with.
/// Name of the repo.
/// Thrown if you attempt to add a repository to a team that is not owned by the organization.
///
/// See the API documentation for more information.
///
/// if the repository was added to the team; otherwise.
public IObservable AddRepository(int id, string organization, string repoName)
{
Ensure.ArgumentNotNullOrEmptyString(organization, "organization");
Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName");
return _client.AddRepository(id, organization, repoName).ToObservable();
}
///
/// Adds a to a .
///
/// The team identifier.
/// Org to associate the repo with.
/// Name of the repo.
/// The permission to grant the team on this repository.
/// Thrown if you attempt to add a repository to a team that is not owned by the organization.
///
/// See the API documentation for more information.
///
/// if the repository was added to the team; otherwise.
public IObservable AddRepository(int id, string organization, string repoName, RepositoryPermissionRequest permission)
{
Ensure.ArgumentNotNullOrEmptyString(organization, "organization");
Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName");
return _client.AddRepository(id, organization, repoName, permission).ToObservable();
}
///
/// Remove a repository from the team
///
/// Thrown when a general API error occurs.
///
public IObservable RemoveRepository(int id, string organization, string repoName)
{
Ensure.ArgumentNotNullOrEmptyString(organization, "organization");
Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName");
return _client.RemoveRepository(id, organization, repoName).ToObservable();
}
///
/// Gets whether or not the given repository is managed by the given team.
///
/// The team identifier
/// Owner of the org the team is associated with.
/// Name of the repo.
///
/// See the API documentation for more information.
///
/// if the repository is managed by the given team; otherwise.
public IObservable IsRepositoryManagedByTeam(int id, string owner, string repo)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
return _client.IsRepositoryManagedByTeam(id, owner, repo).ToObservable();
}
}
}