Esempio n. 1
0
        private async Task GetLink()
        {
            await SpinnerEx.StartAsync("Looking for an awesome article..", async spinner =>
            {
                try
                {
                    Blog blog = new Blog();

                    HttpClient client = new HttpClient();
                    string url        = "https://discoverdot.net/data/blogs.json";
                    string content    = await client.GetStringAsync(url);

                    var blogList = JsonConvert.DeserializeObject <List <Blog> >(content);
                    Random rnd   = new Random();
                    blog         = blogList[rnd.Next(0, blogList.Count - 1)];

                    var cow        = Cow.GetCow();
                    var bubbleText = blog.title + Environment.NewLine + blog.newestFeedItem.title + Environment.NewLine + blog.newestFeedItem.link;
                    string SpeechBubbleReturned = SpeechBubble.ReturnSpeechBubble(bubbleText, new SayBubbleChars(), blog.newestFeedItem.link.Length);
                    Console.WriteLine(Environment.NewLine + SpeechBubbleReturned + Environment.NewLine + cow);
                }
                catch
                {
                    spinner.Fail("Something went wrong, please try again");
                }
            });
        }
Esempio n. 2
0
        private int OnExecute()
        {
            var                 cow      = Cow.GetCow();
            HttpClient          client   = new HttpClient();
            string              url      = "https://discoverdot.net/data/blogs.json";
            HttpResponseMessage response = client.GetAsync(url).Result;
            string              content  = response.Content.ReadAsStringAsync().Result;

            var blogList = JsonConvert.DeserializeObject <List <Blog> >(content);


            Random rnd  = new Random();
            var    blog = blogList[rnd.Next(0, blogList.Count - 1)];


            var    bubbleText           = blog.title + Environment.NewLine + blog.newestFeedItem.title + Environment.NewLine + blog.newestFeedItem.link;
            string SpeechBubbleReturned = SpeechBubble.ReturnSpeechBubble(bubbleText, new SayBubbleChars(), blog.newestFeedItem.link.Length);

            Console.WriteLine(SpeechBubbleReturned + Environment.NewLine + cow);

            return(0);
        }