Skip to content

Commit

Permalink
Merge pull request #108 from IrvinDominin/master
Browse files Browse the repository at this point in the history
Added GoTCharacters
  • Loading branch information
aherd2985 authored Oct 12, 2022
2 parents 414de5f + 1551be0 commit 3bafe70
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Models/GoTCharactersModel.cs
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; }
}
}
57 changes: 57 additions & 0 deletions Utilities/GoTCharacters.cs
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");
}
}
}
}

0 comments on commit 3bafe70

Please sign in to comment.