Skip to content

Commit

Permalink
Merge pull request #51 from IrvinDominin/master
Browse files Browse the repository at this point in the history
Case 23 - Breaking Bad quotes
  • Loading branch information
aherd2985 authored Oct 6, 2020
2 parents 0b31ce5 + 14c9414 commit 4c5a8cd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Models/BreakingBadQuoteModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace UtilityBelt.Models
{
class BreakingBadQuoteModel
{
[JsonPropertyName("quote")]
public string Quote { get; set; }
[JsonPropertyName("author")]
public string Author { get; set; }
}
}
30 changes: 30 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
Expand Down Expand Up @@ -92,6 +93,7 @@ static void MenuOptions(IOptions<SecretsModel> options)
Console.WriteLine("20) Console Calculator");
Console.WriteLine("21) Gender from name");
Console.WriteLine("22) Random Dad Joke");
Console.WriteLine("23) Breaking Bad");
Console.WriteLine("");

Console.Write("Your choice:");
Expand Down Expand Up @@ -224,6 +226,12 @@ static void MenuOptions(IOptions<SecretsModel> options)
DadJoke();
break;

case "23":
case "breaking bad":
BreakingBadQuotes();
break;


default:
Console.WriteLine("Please make a valid option");
MenuOptions(options);
Expand Down Expand Up @@ -902,6 +910,28 @@ static void DadJoke()
}
#endregion

#region Breaking Bad Quotes
static void BreakingBadQuotes()
{
IWebProxy defaultWebProxy = WebRequest.DefaultWebProxy;
defaultWebProxy.Credentials = CredentialCache.DefaultCredentials;

string content = string.Empty;
string breakingBadQuoteUrl = $"https://breaking-bad-quotes.herokuapp.com/v1/quotes";
using (var wc = new WebClient() { Proxy = defaultWebProxy })
{
content = wc.DownloadString(breakingBadQuoteUrl);
}

List<BreakingBadQuoteModel> quote = JsonSerializer.Deserialize<List<BreakingBadQuoteModel>>(content);
Console.WriteLine();
Console.WriteLine(@$"Quote -- {quote.FirstOrDefault().Quote}");
Console.WriteLine(@$"From -- {quote.FirstOrDefault().Author}");

Console.WriteLine();
}
#endregion

#region Utility
internal class WebHookContent
{
Expand Down

0 comments on commit 4c5a8cd

Please sign in to comment.