Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Random User #56

Merged
merged 1 commit into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Models/RandomUser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace UtilityBelt.Models
{
public class Name
{
public string title { get; set; }
public string first { get; set; }
public string last { get; set; }
}

public class Result
{
public string gender { get; set; }
public Name name { get; set; }
public string email { get; set; }
public string phone { get; set; }
public string cell { get; set; }
public string nat { get; set; }
}

public class Info
{
public string seed { get; set; }
public int results { get; set; }
public int page { get; set; }
public string version { get; set; }
}

public class RandomUser
{
[JsonPropertyName("results")]
public List<Result> results { get; set; }
[JsonPropertyName("info")]
public Info info { get; set; }
}


}
32 changes: 32 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static void MenuOptions(IOptions<SecretsModel> options)
Console.WriteLine("24) Fun Ghost Game");
Console.WriteLine("25) Dns Hostname to IP Address");
Console.WriteLine("26) Panda Fact");
Console.WriteLine("27) Random User Generator");
Console.WriteLine("");

Console.Write("Your choice:");
Expand Down Expand Up @@ -249,6 +250,11 @@ static void MenuOptions(IOptions<SecretsModel> options)
case "panda":
RandomPandaFact();
break;

case "27":
case "random user generator":
RandomUserGenerator();
break;

default:
Console.WriteLine("Please make a valid option");
Expand Down Expand Up @@ -1048,6 +1054,32 @@ static void BreakingBadQuotes()
#endregion
#endregion

#region Random User Generator
static void RandomUserGenerator()
{
string content = string.Empty;
string randomUserUrl = @"https://randomuser.me/api";
using (var wc = new WebClient())
{
content = wc.DownloadString(randomUserUrl);
}

RandomUser randomUser = JsonSerializer.Deserialize<RandomUser>(content);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Cyan;

foreach(var user in randomUser.results)
{
Console.WriteLine($"Gender: {user.gender}");
Console.WriteLine($"Name: {user.name.first} {user.name.last}");
Console.WriteLine($"Email: {user.email}");
Console.WriteLine($"Phone: {user.phone}");
}

Console.WriteLine();
}
#endregion

#region Utility
internal class WebHookContent
{
Expand Down