-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from strawberries73/Issue-42
Issue 42 - Added Elephant Facts Utility
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace UtilityBelt.Models | ||
{ | ||
class ElephantModel | ||
{ | ||
[JsonPropertyName("_id")] | ||
public string Id { get; set; } | ||
[JsonPropertyName("index")] | ||
public int Index { get; set; } | ||
[JsonPropertyName("name")] | ||
public string ElephantName { get; set; } | ||
[JsonPropertyName("affiliation")] | ||
public string Affiliation { get; set; } | ||
[JsonPropertyName("species")] | ||
public string Species { get; set; } | ||
[JsonPropertyName("sex")] | ||
public string Sex { get; set; } | ||
[JsonPropertyName("fictional")] | ||
public string Fictional { get; set; } | ||
[JsonPropertyName("dob")] | ||
public string DateOfBirth { get; set; } | ||
[JsonPropertyName("dod")] | ||
public string DateOfDeath { get; set; } | ||
[JsonPropertyName("wikilink")] | ||
public string Wikilink { get; set; } | ||
[JsonPropertyName("image")] | ||
public string Image { get; set; } | ||
[JsonPropertyName("note")] | ||
public string Note { get; set; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string> Commands => new List<string> { "elephant", "elephant facts" }; | ||
|
||
public string Name => "Elephant facts"; | ||
|
||
public void Configure(IOptions<SecretsModel> 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<ElephantModel> elephants = new List<ElephantModel>(); | ||
try | ||
{ | ||
elephants = JsonSerializer.Deserialize<List<ElephantModel>>(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); | ||
} | ||
|
||
} | ||
} | ||
} |