Esempio n. 1
0
        private static async Task <ListOfQuotes> GetSpecificQuote(string path)
        {
            ListOfQuotes        quotes   = null;
            HttpResponseMessage response = await client.GetAsync(path);

            if (response.IsSuccessStatusCode)
            {
                quotes = await response.Content.ReadAsAsync <ListOfQuotes>();
            }
            return(quotes);
        }
Esempio n. 2
0
        private static async Task GetTheNewThing(String tag)
        {
            if (tag == "")
            {
                try
                {
                    Quote quote = new Quote();
                    quote = await GetRandomQuote(client.BaseAddress + "/random/quote");

                    Console.WriteLine($"At {quote.appeared_at.Date.ToShortDateString()} he said: " + quote.value);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else
            {
                try
                {
                    ListOfQuotes list = await GetSpecificQuote(client.BaseAddress + "search/quote?query=" + tag);

                    if (list.Count == 0)
                    {
                        Console.WriteLine($" ---------- The idiot has nothing to say about this. Thank god.");
                    }
                    else
                    {
                        Console.WriteLine($" ---------- The idiot has {list.Count} things to say about this. Yikes.");
                        foreach (Quote quote in list._embedded.quotes)
                        {
                            Console.ReadLine();

                            Console.WriteLine($"At {quote.appeared_at.Date.ToShortDateString()} he said: " + quote.value);
                        }
                        Console.WriteLine(" --------- And that is all he had to say about it!");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }