using System;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
///
/// A client for GitHub Applications API.
///
///
/// See the GitHub Apps API documentation for more information.
///
public class ObservableGitHubAppsClient : IObservableGitHubAppsClient
{
private readonly IGitHubAppsClient _client;
private readonly IConnection _connection;
public ObservableGitHubAppsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
Installation = new ObservableGitHubAppInstallationsClient(client);
_client = client.GitHubApps;
_connection = client.Connection;
}
///
/// Access GitHub's Apps Installations API.
///
///
/// Refer to the API documentation for more information: https://developer.github.com/v3/apps/installations/
///
public IObservableGitHubAppInstallationsClient Installation { get; private set; }
///
/// Get a single GitHub App (if private, requires Personal Access Token or GitHubApp auth)
///
/// https://developer.github.com/v3/apps/#get-a-single-github-app
/// The URL-friendly name of your GitHub App. You can find this on the settings page for your GitHub App.
public IObservable Get(string slug)
{
Ensure.ArgumentNotNullOrEmptyString(slug, nameof(slug));
return _client.Get(slug).ToObservable();
}
///
/// Returns the GitHub App associated with the authentication credentials used (requires GitHubApp auth).
///
/// https://developer.github.com/v3/apps/#get-the-authenticated-github-app
public IObservable GetCurrent()
{
return _client.GetCurrent().ToObservable();
}
///
/// List installations of the authenticated GitHub App (requires GitHubApp auth).
///
/// https://developer.github.com/v3/apps/#find-installations
public IObservable GetAllInstallationsForCurrent()
{
return GetAllInstallationsForCurrent(ApiOptions.None);
}
///
/// List installations of the authenticated GitHub App (requires GitHubApp auth).
///
/// Options for changing the API response
/// https://developer.github.com/v3/apps/#find-installations
public IObservable GetAllInstallationsForCurrent(ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, options);
}
///
/// Get a single GitHub App Installation (requires GitHubApp auth).
///
/// https://developer.github.com/v3/apps/#get-a-single-installation
/// The Id of the GitHub App Installation
[Obsolete("This method will be removed in a future release. Please use GetInstallationForCurrent() instead")]
public IObservable GetInstallation(long installationId)
{
return GetInstallationForCurrent(installationId);
}
///
/// Get a single GitHub App Installation (requires GitHubApp auth).
///
/// https://developer.github.com/v3/apps/#get-a-single-installation
/// The Id of the GitHub App Installation
public IObservable GetInstallationForCurrent(long installationId)
{
return _client.GetInstallationForCurrent(installationId).ToObservable();
}
///
/// List installations for the currently authenticated user (requires GitHubApp User-To-Server Auth).
///
/// https://developer.github.com/v3/apps/#list-installations-for-user
public IObservable GetAllInstallationsForCurrentUser()
{
return _connection.GetAndFlattenAllPages(ApiUrls.UserInstallations());
}
///
/// List installations for the currently authenticated user (requires GitHubApp User-To-Server Auth).
///
/// https://developer.github.com/v3/apps/#list-installations-for-user
public IObservable GetAllInstallationsForCurrentUser(ApiOptions options)
{
return _connection.GetAndFlattenAllPages(ApiUrls.UserInstallations(), options);
}
///
/// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp auth).
///
///
/// https://developer.github.com/v3/apps/#create-a-new-installation-token
/// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation
/// https://developer.github.com/v3/apps/available-endpoints/
///
/// The Id of the GitHub App Installation
public IObservable CreateInstallationToken(long installationId)
{
return _client.CreateInstallationToken(installationId).ToObservable();
}
///
/// Enables an authenticated GitHub App to find the organization's installation information (requires GitHubApp auth).
///
/// https://developer.github.com/v3/apps/#find-organization-installation
/// The name of the organization
public IObservable GetOrganizationInstallationForCurrent(string organization)
{
Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization));
return _client.GetOrganizationInstallationForCurrent(organization).ToObservable();
}
///
/// Enables an authenticated GitHub App to find the repository's installation information (requires GitHubApp auth).
///
/// https://developer.github.com/v3/apps/#find-repository-installation
/// The owner of the repo
/// The name of the repo
public IObservable GetRepositoryInstallationForCurrent(string owner, string repo)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(repo, nameof(repo));
return _client.GetRepositoryInstallationForCurrent(owner, repo).ToObservable();
}
///
/// Enables an authenticated GitHub App to find the repository's installation information (requires GitHubApp auth).
///
/// https://developer.github.com/v3/apps/#find-repository-installation
/// The Id of the repository
public IObservable GetRepositoryInstallationForCurrent(long repositoryId)
{
return _client.GetRepositoryInstallationForCurrent(repositoryId).ToObservable();
}
///
/// Enables an authenticated GitHub App to find the users's installation information (requires GitHubApp auth).
///
/// https://developer.github.com/v3/apps/#find-user-installation
/// The name of the user
public IObservable GetUserInstallationForCurrent(string user)
{
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
return _client.GetUserInstallationForCurrent(user).ToObservable();
}
///
/// Creates a GitHub app by completing the handshake necessary when implementing the GitHub App Manifest flow.
/// https://docs.github.com/apps/sharing-github-apps/registering-a-github-app-from-a-manifest
///
/// https://docs.github.com/rest/apps/apps#create-a-github-app-from-a-manifest
/// Temporary code in a code parameter.
public IObservable CreateAppFromManifest(string code)
{
Ensure.ArgumentNotNullOrEmptyString(code, nameof(code));
return _client.CreateAppFromManifest(code).ToObservable();
}
}
}