Beispiel #1
0
        private static void GetNames()
        {
            new JsonFeed();
            dynamic result = JsonFeed.Getnames();

            names = Tuple.Create(result.name.ToString(), result.surname.ToString());
        }
Beispiel #2
0
        public async Task <string []> GetRandomJokes(Tuple <string, string> names, string category, int number)
        {
            var jsonFeed = new JsonFeed("https://api.chucknorris.io");
            var results  = await jsonFeed.GetRandomJokes(names?.Item1, names?.Item2, category, number).ConfigureAwait(false);

            return(results);
        }
Beispiel #3
0
        private static void GetNames()
        {
            new JsonFeed("http://uinames.com/api", 0);
            dynamic result = JsonFeed.GetName();

            name = Tuple.Create(result.name.ToString(), result.surname.ToString());
        }
Beispiel #4
0
        /// <summary>Retreives a joke from the supplied URL and name replaces when given a true argument</summary>
        /// <param name="useFakeName">A boolean to determine whether to call GetName()</param>
        private static async Task GetRandomJoke(Boolean withFakeName = false)
        {
            string formattedJoke = await JsonFeed.GetRandomJoke();

            if (withFakeName)
            {
                dynamic response = await GetName();

                // Replace first and last name separately as some jokes use first and/or last name separately
                // ex. They don't call him Chuck.... or ... Mr. Norris.
                string firstName = response["name"];
                string lastName  = response["surname"];

                // Replace does not play nice with direct object property
                formattedJoke = Regex.Replace(formattedJoke, "(?i)Chuck", firstName);
                formattedJoke = Regex.Replace(formattedJoke, "(?i)Norris", lastName);

                // Accommodate for female names, and his/her gender designation in the joke
                if (response["gender"] == "female")
                {
                    formattedJoke = formattedJoke.Replace(" He ", " She ");
                    formattedJoke = formattedJoke.Replace(" he ", " she ");
                    formattedJoke = formattedJoke.Replace(" His ", " Her ");
                    formattedJoke = formattedJoke.Replace(" his ", " her ");
                    formattedJoke = formattedJoke.Replace(" Him ", " Her ");
                    formattedJoke = formattedJoke.Replace(" him ", " her ");
                }
            }

            joke = formattedJoke;
        }
Beispiel #5
0
        ///<summary>
        /// Get Jokes Flow
        ///</summary>
        private static void GetJokes(string catName)
        {
            Console.WriteLine("Please enter a name or leave blank to invoke using Chuck Norris\n");
            string name = Console.ReadLine();

            Console.WriteLine("How many jokes do you want? 1-9\n");
            int numOfJokes = 1;

            try{
                numOfJokes = Convert.ToInt32(Console.ReadLine());
                if (numOfJokes > 9)
                {
                    numOfJokes = 1;
                    throw new Exception();
                }
            }
            catch (Exception e) {
                Console.WriteLine("Invalid Entry. Chuck says you get one joke\n");
            }


            try{
                List <String> jokes = JsonFeed.GetRandomJokesByCategory(catName, numOfJokes).Result;
                //Print out list of jokes. If the user provided a substitue name, replace Chuck norris with it
                foreach (string joke in jokes)
                {
                    Console.WriteLine(!string.IsNullOrEmpty(name)?joke.Replace("Chuck Norris", name) : joke);
                }
            }
            catch (Exception e) {
                Console.WriteLine("Error retriving jokes. Please try again later or contact Chuck directly.");
            }
        }
Beispiel #6
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();
            }
        }
Beispiel #7
0
        public async Task <Tuple <string, string> > GetNames()
        {
            var     jsonFeed = new JsonFeed("https://www.names.privserv.com/api/");
            dynamic result   = await jsonFeed.GetNames().ConfigureAwait(false);

            return(Tuple.Create(result.name.ToString(), result.surname.ToString()));
        }
Beispiel #8
0
        private static void GetNames()
        {
            new JsonFeed("https://www.names.privserv.com/api/", 0);
            dynamic result = JsonFeed.Getnames();

            names = Tuple.Create(result.name.ToString(), result.surname.ToString());
        }
Beispiel #9
0
        private static Tuple <string, string, string> GetNames()
        {
            new JsonFeed("https://randomuser.me/api/?format=json/");
            dynamic result = JsonFeed.Getnames();

            return(Tuple.Create(result.results[0].name.first.ToString(), result.results[0].name.last.ToString(),
                                result.results[0].gender.ToString()));
        }
Beispiel #10
0
 private static void getCategories()
 {
     new JsonFeed("https://api.chucknorris.io/jokes/");
     string[] cat = JsonFeed.GetCategories();
     foreach (var c in cat)
     {
         categories.Add(c);
     }
 }
Beispiel #11
0
        /// <summary>
        /// Requests random jokes
        /// </summary>
        /// <param name="category">Category to filter requested jokes if provided</param>
        /// <param name="number">Number to limit amount of requested jokes if provided</param>
        private static void GetRandomJokes(string category, int number)
        {
            List <string> temp = new List <string>();

            for (int i = 0; i < number; i++)
            {
                dynamic result = JsonFeed.GetRandomJokes(names?.Item1, names?.Item2, category);
                temp.Add((string)result);
            }
            results = temp;
        }
Beispiel #12
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;
        }
Beispiel #13
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);
        }
Beispiel #14
0
 private static string[] GetRandomJokes(string category, int number, Tuple <string, string, string> name)
 {
     new JsonFeed("https://api.chucknorris.io");
     return(JsonFeed.GetRandomJokes(name?.Item1, name?.Item2, name?.Item3, category, number));
 }
Beispiel #15
0
 private static void GetRandomJokes(string category, int number)
 {
     new JsonFeed("https://api.chucknorris.io", number);
     results = JsonFeed.GetRandomJokes(names?.Item1, names?.Item2, category);
 }
Beispiel #16
0
 private static void getCategories()
 {
     new JsonFeed("https://api.chucknorris.io", 0);
     results = JsonFeed.GetCategories();
 }
Beispiel #17
0
 private static void GetCategories()
 {
     new JsonFeed("http://api.icndb.com", 0);
     results = JsonFeed.GetCategories();
 }
Beispiel #18
0
 private static void GetRandomJokes(string category, int number)
 {
     new JsonFeed(jokesURL, number);
     results = JsonFeed.GetRandomJokes(names?.Item1, names?.Item2, category);
 }
Beispiel #19
0
 private static void GetRandomJokes(string category, int number)
 {
     new JsonFeed("http://api.icndb.com", number);
     results = JsonFeed.GetRandomJokes(name?.Item1, name?.Item2, category);
 }
Beispiel #20
0
        /// <summary>
        /// Retrieves random name
        /// </summary>
        /// <returns>a tuple of the random name</returns>
        private static Tuple <string, string> GetRandomName()
        {
            dynamic result = new JsonFeed("http://uinames.com/api/").Getname();

            return(Tuple.Create(result.name.ToString(), result.surname.ToString()));
        }
Beispiel #21
0
 /// <summary>
 /// Async get method to retrieve names from uinames.com
 /// </summary>
 /// <returns>A name object</returns>
 private static async Task <dynamic> GetName()
 {
     return(await JsonFeed.Getname());
 }
Beispiel #22
0
 private static void getCategories()
 {
     new JsonFeed();
     results = JsonFeed.GetCategories();
 }
Beispiel #23
0
 private static void GetRandomJokes(string category)
 {
     new JsonFeed();
     results = JsonFeed.GetRandomJokes(names?.Item1, names?.Item2, category);
 }