From 6dc68a29af23e11aa7334b3e1c88deee9274c7e6 Mon Sep 17 00:00:00 2001 From: half-ogre Date: Tue, 15 Oct 2013 11:44:03 -0700 Subject: [PATCH] add API doc for ApiConnection --- Octokit/Http/ApiConnection.cs | 136 +++++++++++++++++++++++++++------ Octokit/Http/IApiConnection.cs | 16 ++-- 2 files changed, 120 insertions(+), 32 deletions(-) diff --git a/Octokit/Http/ApiConnection.cs b/Octokit/Http/ApiConnection.cs index 555fd4f9..0c40126e 100644 --- a/Octokit/Http/ApiConnection.cs +++ b/Octokit/Http/ApiConnection.cs @@ -6,14 +6,27 @@ using Octokit.Internal; namespace Octokit { + /// + /// A connection for making API requests against URI endpoints. + /// Provides type-friendly convenience methods that wrap methods. + /// public class ApiConnection : IApiConnection { readonly IApiPagination _pagination; + /// + /// Initializes a new instance of the class. + /// + /// A connection for making HTTP requests. public ApiConnection(IConnection connection) : this(connection, new ApiPagination()) { } + /// + /// Initializes a new instance of the class. + /// + /// A connection for making HTTP requests. + /// A paginator for paging API responses. protected ApiConnection(IConnection connection, IApiPagination pagination) { Ensure.ArgumentNotNull(connection, "connection"); @@ -23,41 +36,85 @@ namespace Octokit _pagination = pagination; } + /// + /// Gets the connection for making HTTP requests. + /// protected IConnection Connection { get; private set; } - public async Task Get(Uri endpoint, IDictionary parameters) + /// + /// Gets the API resource at the specified URI. + /// + /// Type of the API resource to get. + /// URI of the API resource to get. + /// Parameters to add to the API request. + /// The API resource. + /// Thrown when an API error occurs. + public async Task Get(Uri uri, IDictionary parameters) { - Ensure.ArgumentNotNull(endpoint, "endpoint"); + Ensure.ArgumentNotNull(uri, "uri"); - var response = await Connection.GetAsync(endpoint, parameters); + var response = await Connection.GetAsync(uri, parameters); return response.BodyAsObject; } - public async Task GetHtml(Uri endpoint, IDictionary parameters) + /// + /// Gets the HTML content of the API resource at the specified URI. + /// + /// URI of the API resource to get. + /// Parameters to add to the API request. + /// The API resource's HTML content. + /// Thrown when an API error occurs. + public async Task GetHtml(Uri uri, IDictionary parameters) { - Ensure.ArgumentNotNull(endpoint, "endpoint"); + Ensure.ArgumentNotNull(uri, "uri"); - var response = await Connection.GetHtml(endpoint, parameters); + var response = await Connection.GetHtml(uri, parameters); return response.Body; } - public async Task> GetAll(Uri endpoint, IDictionary parameters) + /// + /// Gets all API resources in the list at the specified URI. + /// + /// Type of the API resource in the list. + /// URI of the API resource to get. + /// Parameters to add to the API request. + /// of the The API resources in the list. + /// Thrown when an API error occurs. + public async Task> GetAll(Uri uri, IDictionary parameters) { - Ensure.ArgumentNotNull(endpoint, "endpoint"); + Ensure.ArgumentNotNull(uri, "uri"); - return await _pagination.GetAllPages(async () => await GetPage(endpoint, parameters)); + return await _pagination.GetAllPages(async () => await GetPage(uri, parameters)); } - public async Task Post(Uri endpoint, object data) + /// + /// Creates a new API resource in the list at the specified URI. + /// + /// The API resource's type. + /// URI of the API resource to get. + /// Object that describes the new API resource; this will be serialized and used as the request's body. + /// The created API resource. + /// Thrown when an API error occurs. + public async Task Post(Uri uri, object data) { - Ensure.ArgumentNotNull(endpoint, "endpoint"); + Ensure.ArgumentNotNull(uri, "uri"); Ensure.ArgumentNotNull(data, "data"); - var response = await Connection.PostAsync(endpoint, data); + var response = await Connection.PostAsync(uri, data); return response.BodyAsObject; } + /// + /// Creates a new API resource in the list at the specified URI. + /// + /// The API resource's type. + /// URI of the API resource to get. + /// A to use as the API request's body. + /// Content type of the API request. + /// Accept header to use for the API request. + /// The created API resource. + /// Thrown when an API error occurs. public async Task Post(Uri uri, Stream rawData, string contentType, string accepts) { Ensure.ArgumentNotNull(uri, "uri"); @@ -73,42 +130,73 @@ namespace Octokit return response.BodyAsObject; } - public async Task Put(Uri endpoint, object data) + /// + /// Creates or replaces the API resource at the specified URI. + /// + /// The API resource's type. + /// URI of the API resource to create or replace. + /// Object that describes the API resource; this will be serialized and used as the request's body. + /// The created API resource. + /// Thrown when an API error occurs. + public async Task Put(Uri uri, object data) { - Ensure.ArgumentNotNull(endpoint, "endpoint"); + Ensure.ArgumentNotNull(uri, "uri"); Ensure.ArgumentNotNull(data, "data"); - var response = await Connection.PutAsync(endpoint, data); + var response = await Connection.PutAsync(uri, data); return response.BodyAsObject; } - public async Task Put(Uri endpoint, object data, string twoFactorAuthenticationCode) + /// + /// Creates or replaces the API resource at the specified URI. + /// + /// The API resource's type. + /// URI of the API resource to create or replace. + /// Object that describes the API resource; this will be serialized and used as the request's body. + /// The two-factor authentication code in response to the current user's previous challenge. + /// The created API resource. + /// Thrown when an API error occurs. + public async Task Put(Uri uri, object data, string twoFactorAuthenticationCode) { - Ensure.ArgumentNotNull(endpoint, "endpoint"); + Ensure.ArgumentNotNull(uri, "endpoint"); Ensure.ArgumentNotNull(data, "data"); Ensure.ArgumentNotNullOrEmptyString(twoFactorAuthenticationCode, "twoFactorAuthenticationCode"); - var response = await Connection.PutAsync(endpoint, data, twoFactorAuthenticationCode); + var response = await Connection.PutAsync(uri, data, twoFactorAuthenticationCode); return response.BodyAsObject; } - public async Task Patch(Uri endpoint, object data) + /// + /// Updates the API resource at the specified URI. + /// + /// The API resource's type. + /// URI of the API resource to update. + /// /// Object that describes the API resource; this will be serialized and used as the request's body. + /// The updated API resource. + /// Thrown when an API error occurs. + public async Task Patch(Uri uri, object data) { - Ensure.ArgumentNotNull(endpoint, "endpoint"); + Ensure.ArgumentNotNull(uri, "endpoint"); Ensure.ArgumentNotNull(data, "data"); - var response = await Connection.PatchAsync(endpoint, data); + var response = await Connection.PatchAsync(uri, data); return response.BodyAsObject; } - public async Task Delete(Uri endpoint) + /// + /// Deletes the API object at the specified URI. + /// + /// The API resource's type. + /// URI of the API resource to delete. + /// A for the request's execution. + public async Task Delete(Uri uri) { - Ensure.ArgumentNotNull(endpoint, "endpoint"); + Ensure.ArgumentNotNull(uri, "endpoint"); - await Connection.DeleteAsync(endpoint); + await Connection.DeleteAsync(uri); } async Task> GetPage(Uri endpoint, IDictionary parameters) diff --git a/Octokit/Http/IApiConnection.cs b/Octokit/Http/IApiConnection.cs index 2d199095..86811bf9 100644 --- a/Octokit/Http/IApiConnection.cs +++ b/Octokit/Http/IApiConnection.cs @@ -13,15 +13,15 @@ namespace Octokit { [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "It's fiiiine. It's fine. Trust us.")] - Task Get(Uri endpoint, IDictionary parameters); - Task GetHtml(Uri endpoint, IDictionary parameters); - Task> GetAll(Uri endpoint, IDictionary parameters); - Task Post(Uri endpoint, object data); + Task Get(Uri uri, IDictionary parameters); + Task GetHtml(Uri uri, IDictionary parameters); + Task> GetAll(Uri uri, IDictionary parameters); + Task Post(Uri uri, object data); Task Post(Uri uri, Stream rawData, string contentType, string accepts); - Task Put(Uri endpoint, object data); - Task Put(Uri endpoint, object data, string twoFactorAuthenticationCode); - Task Patch(Uri endpoint, object data); + Task Put(Uri uri, object data); + Task Put(Uri uri, object data, string twoFactorAuthenticationCode); + Task Patch(Uri uri, object data); [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification="Legitimate, but I'm not fixing it just yet.")] - Task Delete(Uri endpoint); + Task Delete(Uri uri); } } \ No newline at end of file