From 596cba3d15e7f0c6516fbc0fcd8df299c6f97005 Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Mon, 22 Aug 2016 15:04:01 +0100 Subject: [PATCH] Document some more of the REST client stuff --- src/Discord.Net/Net/Rest/DefaultRestClient.cs | 8 +++++--- src/Discord.Net/Net/Rest/IRestClient.cs | 5 +++++ src/Discord.Net/Net/Rest/RestClientProvider.cs | 1 + src/Discord.Net/Rest/DiscordRestConfig.cs | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net/Net/Rest/DefaultRestClient.cs b/src/Discord.Net/Net/Rest/DefaultRestClient.cs index daaa2ba96..4f0d8b436 100644 --- a/src/Discord.Net/Net/Rest/DefaultRestClient.cs +++ b/src/Discord.Net/Net/Rest/DefaultRestClient.cs @@ -58,27 +58,28 @@ namespace Discord.Net.Rest Dispose(true); } - /// Sets a header to be used in REST requests. + /// public void SetHeader(string key, string value) { _client.DefaultRequestHeaders.Remove(key); if (value != null) _client.DefaultRequestHeaders.Add(key, value); } - /// Sets the global cancellation token for any requests made by this instance. + /// public void SetCancelToken(CancellationToken cancelToken) { _parentToken = cancelToken; _cancelToken = CancellationTokenSource.CreateLinkedTokenSource(_parentToken, _cancelTokenSource.Token).Token; } - /// Sends a request with no body to the given endpoint. + /// public async Task SendAsync(string method, string endpoint, bool headerOnly = false) { string uri = Path.Combine(_baseUrl, endpoint); using (var restRequest = new HttpRequestMessage(GetMethod(method), uri)) return await SendInternalAsync(restRequest, headerOnly).ConfigureAwait(false); } + /// public async Task SendAsync(string method, string endpoint, string json, bool headerOnly = false) { string uri = Path.Combine(_baseUrl, endpoint); @@ -88,6 +89,7 @@ namespace Discord.Net.Rest return await SendInternalAsync(restRequest, headerOnly).ConfigureAwait(false); } } + /// public async Task SendAsync(string method, string endpoint, IReadOnlyDictionary multipartParams, bool headerOnly = false) { string uri = Path.Combine(_baseUrl, endpoint); diff --git a/src/Discord.Net/Net/Rest/IRestClient.cs b/src/Discord.Net/Net/Rest/IRestClient.cs index 57b5f91ca..51a2a33d5 100644 --- a/src/Discord.Net/Net/Rest/IRestClient.cs +++ b/src/Discord.Net/Net/Rest/IRestClient.cs @@ -8,11 +8,16 @@ namespace Discord.Net.Rest //TODO: Add docstrings public interface IRestClient { + /// Sets a header to be used in REST requests. void SetHeader(string key, string value); + /// Sets the global cancellation token for any requests made by this instance. void SetCancelToken(CancellationToken cancelToken); + /// Sends a request with no body to the given endpoint. Task SendAsync(string method, string endpoint, bool headerOnly = false); + /// Sends a request with a body to the given endpoint. Task SendAsync(string method, string endpoint, string json, bool headerOnly = false); + /// Sends a multipart request with the given parameters to the given endpoint. Task SendAsync(string method, string endpoint, IReadOnlyDictionary multipartParams, bool headerOnly = false); } } diff --git a/src/Discord.Net/Net/Rest/RestClientProvider.cs b/src/Discord.Net/Net/Rest/RestClientProvider.cs index 51a7eb619..8377a5255 100644 --- a/src/Discord.Net/Net/Rest/RestClientProvider.cs +++ b/src/Discord.Net/Net/Rest/RestClientProvider.cs @@ -1,4 +1,5 @@ namespace Discord.Net.Rest { + /// A delegate for creating a user-defined implementation of public delegate IRestClient RestClientProvider(string baseUrl); } diff --git a/src/Discord.Net/Rest/DiscordRestConfig.cs b/src/Discord.Net/Rest/DiscordRestConfig.cs index 8dee72231..e6b7056f6 100644 --- a/src/Discord.Net/Rest/DiscordRestConfig.cs +++ b/src/Discord.Net/Rest/DiscordRestConfig.cs @@ -2,8 +2,10 @@ namespace Discord.Rest { + /// A set of common configuration options for REST clients. public class DiscordRestConfig : DiscordConfig { + /// Gets the user agent used in REST API calls public static string UserAgent { get; } = $"DiscordBot (https://github.com/RogueException/Discord.Net, v{Version})"; internal const int RestTimeout = 10000;