SlackEventApiRequester.cs 781 B

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using System.Net.Http;
  3. using System.Text.Json;
  4. using System.Threading.Tasks;
  5. namespace sera_slackbot.Library
  6. {
  7. public class SlackEventApiRequester
  8. {
  9. public async Task<JsonElement> GetJson(string url)
  10. {
  11. var client = new HttpClient();
  12. try
  13. {
  14. var response = await client.GetAsync(url);
  15. var jsonString = await response.Content.ReadAsStringAsync();
  16. return JsonSerializer.Deserialize<dynamic>(jsonString);
  17. }
  18. catch (Exception e)
  19. {
  20. Console.WriteLine("Issue with making the curl; I tried " + url);
  21. Console.WriteLine(e.Message);
  22. }
  23. return new JsonElement();
  24. }
  25. }
  26. }