Files
octokit.net/Octokit/Clients/GitHubAppInstallationsClient.cs
Stanley Goldman 5f1421bd34 Additional GitHub Apps APIs (#1854)
* Adding functionality to query installations for user

* Rename method

* Adding installation methods

* Adding tests

* Adding observable client methods

* Adding InstallationResponse

* Adding GitHub Apps Installations Client

* Tweaking doc comments

* Undoing unintentional changes and cleaning up

* Reordering functions in clients to keep the same code look and feel

* Making sure all methods are documented with their authentication requirements

* Syntax error

* Renaming methods and tests

* Renaming property

* Test cleanup

* XmlDoc comment fixups and consistency

* rename User -To-Server auth methods from xxxForUser to xxxForCurrentUser

* rename GitHubAppsInstallationsClient to GitHubAppInstallationsClient to be consistent with single/plural naming conventions

* make method order match the order on github docs site

* tidy up usings

* correct implementation of GetALlInstallationsForCurrent method to be consistent

* Add missing unit and integration tests for ObservableGitHubAppsClient

* fix renamed method in observable tests

* Add EnsuresNonEmptyArguments tests and fixup asserts in GitHubAppsClient

* Add tests for new Observable client methods and fixup Null/Empty asserts in Observable client

* change non paginated call to call through to other method but with ApiOptions.None

* add unit tests for observable client and fixup errors they found

* add integration tests for new GitHubAppsClient methods, fixed an incorrect route that the tests found!

* add integration tests for extra methods on observable client

* add integration tests for new clients GitHubAppInstallationsClient and ObservableGitHubAppInstallationsClient

* deprecate renamed method properly, to avoid breaking change
2018-09-03 20:36:33 +10:00

70 lines
3.5 KiB
C#

using System.Linq;
using System.Threading.Tasks;
namespace Octokit.Clients
{
/// <summary>
/// A client for GitHub Applications Installations API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/apps/installations/">GitHub Apps Installations API documentation</a> for more information.
/// </remarks>
public class GitHubAppInstallationsClient : ApiClient, IGitHubAppInstallationsClient
{
public GitHubAppInstallationsClient(IApiConnection apiConnection) : base(apiConnection)
{
}
/// <summary>
/// List repositories of the authenticated GitHub App Installation (requires GitHubApp Installation-Token auth).
/// </summary>
/// <remarks>https://developer.github.com/v3/apps/installations/#list-repositories</remarks>
public Task<RepositoriesResponse> GetAllRepositoriesForCurrent()
{
return GetAllRepositoriesForCurrent(ApiOptions.None);
}
/// <summary>
/// List repositories of the authenticated GitHub App Installation (requires GitHubApp Installation-Token auth).
/// </summary>
/// <param name="options">Options for changing the API response</param>
/// <remarks>https://developer.github.com/v3/apps/installations/#list-repositories</remarks>
public async Task<RepositoriesResponse> GetAllRepositoriesForCurrent(ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
var results = await ApiConnection.GetAll<RepositoriesResponse>(ApiUrls.InstallationRepositories(), null, AcceptHeaders.GitHubAppsPreview, options).ConfigureAwait(false);
return new RepositoriesResponse(
results.Count > 0 ? results.Max(x => x.TotalCount) : 0,
results.SelectMany(x => x.Repositories).ToList());
}
/// <summary>
/// List repositories accessible to the user for an installation (requires GitHubApp User-To-Server Auth).
/// </summary>
/// <param name="installationId">The Id of the installation</param>
/// <remarks>https://developer.github.com/v3/apps/installations/#list-repositories-accessible-to-the-user-for-an-installation</remarks>
public Task<RepositoriesResponse> GetAllRepositoriesForCurrentUser(long installationId)
{
return GetAllRepositoriesForCurrentUser(installationId, ApiOptions.None);
}
/// <summary>
/// List repositories accessible to the user for an installation (requires GitHubApp User-To-Server Auth).
/// </summary>
/// <param name="installationId">The Id of the installation</param>
/// <param name="options">Options for changing the API response</param>
/// <remarks>https://developer.github.com/v3/apps/installations/#list-repositories-accessible-to-the-user-for-an-installation</remarks>
public async Task<RepositoriesResponse> GetAllRepositoriesForCurrentUser(long installationId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
var results = await ApiConnection.GetAll<RepositoriesResponse>(ApiUrls.UserInstallationRepositories(installationId), null, AcceptHeaders.GitHubAppsPreview, options).ConfigureAwait(false);
return new RepositoriesResponse(
results.Count > 0 ? results.Max(x => x.TotalCount) : 0,
results.SelectMany(x => x.Repositories).ToList());
}
}
}