Skip to content

Commit

Permalink
Fixed Tronald Dump API
Browse files Browse the repository at this point in the history
  • Loading branch information
Voltstro committed Dec 26, 2019
1 parent 927ca78 commit 720c251
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Pootis-Bot/Helpers/WebUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
7 changes: 5 additions & 2 deletions src/Pootis-Bot/Services/Fun/TronaldDumpService.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,14 +16,15 @@ 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<dynamic>(json);

return dataObject.value.ToString();
}
catch (Exception ex)
{
Logger.Log($"Error occured while trying to get random Trump Quote: {ex.Message}", LogVerbosity.Error);
return "**ERROR**: " + ex.Message;
}
}
Expand All @@ -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<dynamic>(json);
if (dataObject._embedded.quotes.Count == 0) return "No quotes found for that search!";
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 720c251

Please sign in to comment.