diff --git a/src/Pootis-Bot/Helpers/WebUtils.cs b/src/Pootis-Bot/Helpers/WebUtils.cs index 703e4151..4f3e3631 100644 --- a/src/Pootis-Bot/Helpers/WebUtils.cs +++ b/src/Pootis-Bot/Helpers/WebUtils.cs @@ -24,5 +24,16 @@ public static string DownloadString(string url) return content.ReadAsStringAsync().Result; } + + public static string DownloadString(string url, string scheme, string parameter) + { + using HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url); + + requestMessage.Headers.Add(scheme, parameter);; + using HttpResponseMessage response = Global.HttpClient.SendAsync(requestMessage).Result; + using HttpContent content = response.Content; + + return content.ReadAsStringAsync().Result; + } } } \ No newline at end of file diff --git a/src/Pootis-Bot/Services/Fun/TronaldDumpService.cs b/src/Pootis-Bot/Services/Fun/TronaldDumpService.cs index 38e1ab0a..fdb7e7a4 100644 --- a/src/Pootis-Bot/Services/Fun/TronaldDumpService.cs +++ b/src/Pootis-Bot/Services/Fun/TronaldDumpService.cs @@ -1,6 +1,7 @@ using System; using Newtonsoft.Json; using Pootis_Bot.Core; +using Pootis_Bot.Core.Logging; using Pootis_Bot.Helpers; namespace Pootis_Bot.Services.Fun @@ -15,7 +16,7 @@ public static string GetRandomQuote() { try { - string json = WebUtils.DownloadString("https://api.tronalddump.io/random/quote"); + string json = WebUtils.DownloadString("https://api.tronalddump.io/random/quote", "accept", "application/hal+json"); dynamic dataObject = JsonConvert.DeserializeObject(json); @@ -23,6 +24,7 @@ public static string GetRandomQuote() } catch (Exception ex) { + Logger.Log($"Error occured while trying to get random Trump Quote: {ex.Message}", LogVerbosity.Error); return "**ERROR**: " + ex.Message; } } @@ -31,7 +33,7 @@ public static string GetQuote(string search) { try { - string json = WebUtils.DownloadString($"https://api.tronalddump.io/search/quote?query={search}"); + string json = WebUtils.DownloadString($"https://api.tronalddump.io/search/quote?query={search}", "accept", "application/hal+json"); dynamic dataObject = JsonConvert.DeserializeObject(json); if (dataObject._embedded.quotes.Count == 0) return "No quotes found for that search!"; @@ -44,6 +46,7 @@ public static string GetQuote(string search) } catch (Exception ex) { + Logger.Log($"Error occured while trying to get Trump Quote: {ex.Message}", LogVerbosity.Error); return "**ERROR**: " + ex.Message; } }