diff --git a/Utilities/ElephantFacts.cs b/Utilities/ElephantFacts.cs new file mode 100644 index 0000000..e703dba --- /dev/null +++ b/Utilities/ElephantFacts.cs @@ -0,0 +1,56 @@ +using Microsoft.Extensions.Options; +using System; +using System.Collections.Generic; +using System.Composition; +using System.Net; +using System.Text; +using System.Text.Json; +using UtilityBelt.Models; + +namespace UtilityBelt.Utilities +{ + [Export(typeof(IUtility))] + class ElephantFacts : IUtility + { + public IList Commands => new List { "elephant", "elephant facts" }; + + public string Name => "Elephant facts"; + + public void Configure(IOptions options) + { + //throw new NotImplementedException() + } + + public void Run() + { + string content = string.Empty; + + string elephantFactsApi = @"https://elephant-api.herokuapp.com/elephants"; + + using (var wc = new WebClient()) + { + content = wc.DownloadString(elephantFactsApi); + } + + List elephants = new List(); + try + { + elephants = JsonSerializer.Deserialize>(content); + Random random = new Random(); + + int randomNumber = random.Next(0, 46); + + for ( int i = 0; i < 47; i++) + { + Console.WriteLine($"{elephants[i].ElephantName}"); + } + + } + catch (Exception e) + { + Console.WriteLine(e); + } + + } + } +}