/// <summary> /// Internal function for making web requests to the API easier, without a return type. /// </summary> /// <param name="endpoint">The endpoint to send the request to.</param> /// <param name="method">The method to use for the request.</param> /// <param name="queryString">The query string to add on to the request.</param> /// <param name="botStatistics">A <see cref="BotStatistics"/> object for the <see cref="PostStats(string, BotStatisticsPayload)"/> method.</param> private async Task <bool> MakeRequest(string endpoint, HttpMethod method, Dictionary <string, object> queryString = null, BotStatisticsPayload botStatistics = null) { var formattedQs = ""; var contentStr = ""; if (queryString != null) { var keyValuePairs = queryString.Select( x => $"{Uri.EscapeDataString(x.Key)}={Uri.EscapeDataString(x.Value.ToString())}"); formattedQs = $"?{string.Join("&", keyValuePairs)}"; } if (botStatistics != null) { contentStr = JsonConvert.SerializeObject(botStatistics); } var result = await _client.SendAsync(new HttpRequestMessage { RequestUri = new Uri(endpoint + formattedQs), Method = method, Headers = { { HttpRequestHeader.Authorization.ToString(), _apiToken }, { HttpRequestHeader.Accept.ToString(), "application/json" } }, Content = new StringContent(contentStr, Encoding.UTF8, "application/json") }); return(result.IsSuccessStatusCode); }
/// <summary> /// Updates the statistics of a bot. /// </summary> /// <param name="id">The ID of the bot you would like to update the statistics for.</param> /// <param name="payload">A <see cref="BotStatisticsPayload"/> object.</param> /// <returns>Whether or not the statistics were successfully updated.</returns> public Task <bool> PostStats(string id, BotStatisticsPayload payload) => MakeRequest("/bots/" + id + "/stats", HttpMethod.Post, botStatistics: payload);