-
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 #108 from IrvinDominin/master
Added GoTCharacters
- Loading branch information
Showing
2 changed files
with
81 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,24 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace UtilityBelt.Models | ||
{ | ||
class GoTCharactersModel | ||
{ | ||
[JsonPropertyName("id")] | ||
public int Id { get; set; } | ||
[JsonPropertyName("firstName")] | ||
public string FirstName { get; set; } | ||
[JsonPropertyName("lastName")] | ||
public string LastName { get; set; } | ||
[JsonPropertyName("fullName")] | ||
public string FullName { get; set; } | ||
[JsonPropertyName("title")] | ||
public string Title { get; set; } | ||
[JsonPropertyName("family")] | ||
public string Family { get; set; } | ||
[JsonPropertyName("image")] | ||
public string Image { get; set; } | ||
[JsonPropertyName("imageUrl")] | ||
public string ImageUrl { 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,57 @@ | ||
using Microsoft.Extensions.Options; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Composition; | ||
using System.Net; | ||
using System.Text.Json; | ||
using UtilityBelt.Models; | ||
|
||
namespace UtilityBelt.Utilities | ||
{ | ||
[Export(typeof(IUtility))] | ||
internal class GoTCharacters : IUtility | ||
{ | ||
public IList<string> Commands => new List<string> { "GoT", "Thrones" }; | ||
|
||
public string Name => "GOT Characters"; | ||
|
||
public void Configure(IOptions<SecretsModel> options) | ||
{ | ||
} | ||
|
||
public void Run() | ||
{ | ||
string content = string.Empty; | ||
int numberEntered; | ||
|
||
Console.WriteLine("Please enter an integer number"); | ||
String userInput = Console.ReadLine(); | ||
|
||
GoTCharactersModel goTCharacter = new GoTCharactersModel(); | ||
|
||
if (int.TryParse(userInput, out numberEntered)) | ||
{ | ||
try | ||
{ | ||
string goTApiURL = $"https://thronesapi.com/api/v2/Characters/{userInput}"; | ||
using (var wc = new WebClient()) | ||
{ | ||
content = wc.DownloadString(goTApiURL); | ||
} | ||
|
||
goTCharacter = JsonSerializer.Deserialize<GoTCharactersModel>(content); | ||
|
||
Console.WriteLine($"Well done you found {goTCharacter?.FullName} - {goTCharacter?.Title}"); | ||
} | ||
catch | ||
{ | ||
Console.WriteLine("You don't know nothing Jon Snow"); | ||
} | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Input was not an integer"); | ||
} | ||
} | ||
} | ||
} |