Ejemplo n.º 1
0
        ///<summary>
        /// Get Jokes By Category Flow, will call get jokes flow
        ///</summary>
        private static void GetJokesByCategory()
        {
            Dictionary <int, string> categories = new Dictionary <int, string>();

            try{
                categories = JsonFeed.GetCategories().Result;
            }
            catch (Exception e) {
                Console.WriteLine("Error retrieving joke categories please try again later");
            }
            //Present user with a menu to allow them to select Joke Category
            Console.WriteLine("Please select a category");
            foreach (KeyValuePair <int, string> cat in categories)
            {
                Console.WriteLine("{0} {1}", cat.Key, cat.Value);
            }

            try{
                var result = Console.ReadLine();
                int catVal = Convert.ToInt32(result);
                //Use the text value of the category name key they provided as required by endpoint
                string catName = categories[catVal];
                GetJokes(catName);
            }
            catch (KeyNotFoundException knfe) {
                Console.WriteLine("Invalid category selected.");
            }
            catch (Exception e) {
                Console.WriteLine("Error retriving jokes. Please try again later or contact Chuck directly.");
                clearApp();
            }
        }
Ejemplo n.º 2
0
 private static void getCategories()
 {
     new JsonFeed("https://api.chucknorris.io/jokes/");
     string[] cat = JsonFeed.GetCategories();
     foreach (var c in cat)
     {
         categories.Add(c);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Requests joke categories
        /// </summary>
        private static void GetCategories()
        {
            dynamic       result = JsonFeed.GetCategories();
            List <string> temp   = new List <string>();

            foreach (string category in result)
            {
                temp.Add(category);
            }
            results = temp;
        }
Ejemplo n.º 4
0
        public async Task <string[]> GetCategories()
        {
            string [] rc = new string[50];
            if (!CachedCategories.Any())
            {
                var jsonFeed = new JsonFeed("https://api.chucknorris.io");
                rc = await jsonFeed.GetCategories().ConfigureAwait(false);

                CachedCategories.AddRange(rc);
            }
            else
            {
                rc = CachedCategories.ToArray();
            }
            return(rc);
        }
Ejemplo n.º 5
0
 private static void getCategories()
 {
     new JsonFeed("https://api.chucknorris.io", 0);
     results = JsonFeed.GetCategories();
 }
Ejemplo n.º 6
0
 private static void GetCategories()
 {
     new JsonFeed("http://api.icndb.com", 0);
     results = JsonFeed.GetCategories();
 }
Ejemplo n.º 7
0
 private static void getCategories()
 {
     new JsonFeed();
     results = JsonFeed.GetCategories();
 }
Ejemplo n.º 8
0
 /* Method for getting the category values from the API and setting it to HashSet<string> object*/
 private static void getCategories()
 {
     reqObj.setURL("https://api.chucknorris.io/jokes/");
     categories = reqObj.GetCategories();
 }