Пример #1
0
        public IEnumerable <QuoteFmItem> updateRecommendations()
        {
            decimal            maxKnownId      = 0;
            List <QuoteFmItem> newQuoteFmItems = new List <QuoteFmItem>();

            if (Recommendations.Count > 0)
            {
                maxKnownId = Recommendations.Max(r => r.Id);
            }
            ListOfRecommendations listOfRecommendations = QuoteSharp.API.getRecommendationsListByUser(this.username);

            if (listOfRecommendations != null)
            {
                if (listOfRecommendations.entities.Count() > 0)
                {
                    IEnumerable <Recommendation> newRecommendations = listOfRecommendations.entities.Where(r => r.id > maxKnownId);
                    foreach (Recommendation recommendation in newRecommendations)
                    {
                        QuoteFmItem newItem = QuoteFmItem.createFromApi(recommendation);
                        if (newItem != null)
                        {
                            Recommendations.Add(newItem);
                            newQuoteFmItems.Add(newItem);
                        }
                    }
                }
            }
            return(newQuoteFmItems);
        }
Пример #2
0
        static void Main(string[] args)
        {
            /* This is quite simple testing
             *
             * Methodes do return NULL is no result is available - I do not check here but you should in your application...
             * I decided to create own objects for every result so you can easily see all attributes in debug
             * And I decided to keep this test code very, very simple (no extra methods / functions)
             *
             */
            Console.WriteLine("Test tool for API calls in Quote#");
            Console.WriteLine("###################\n");
            // Categories
            ListOfCategories listCategories = API.getCategories();

            Console.WriteLine("-> List of categories");
            foreach (Category category in listCategories.entities)
            {
                Console.WriteLine(" " + category.ToString());
            }

            Console.WriteLine("\n###################\n");
            Console.WriteLine("-> Recommendations\n");
            // Recommendations
            int id = 900;

            Console.Write("Id of recommendation to fetch (default is 900): ");
            string idString = Console.ReadLine();

            try
            {
                id = Convert.ToInt32(idString);
            }
            catch
            {
                Console.WriteLine("Using default 900");
                id = 900;
            }
            Recommendation reco = API.getRecommendation(id);

            Console.WriteLine(reco.ToString() + "\n");

            Console.Write("Id of article to fetch recommendations of (default is 123): ");
            idString = Console.ReadLine();
            try
            {
                id = Convert.ToInt32(idString);
            }
            catch
            {
                Console.WriteLine("Using default 123");
                id = 123;
            }
            ListOfRecommendations listRecosArticle = API.getRecommendationsListByArticle(id);

            Console.WriteLine("Fetched for article " + listRecosArticle.article.ToString());
            foreach (Recommendation recoInArticle in listRecosArticle.entities)
            {
                Console.WriteLine(" " + recoInArticle.ToString());
            }

            Console.Write("\nUsername to fetch recommendations of (default is quotefm): ");
            string username = Console.ReadLine();

            if (string.IsNullOrEmpty(username))
            {
                Console.WriteLine("Using default username quotefm");
                username = "******";
            }
            ListOfRecommendations listRecosUser = API.getRecommendationsListByUser(username);

            Console.WriteLine("Fetched for username " + username);
            foreach (Recommendation recoOfUser in listRecosUser.entities)
            {
                Console.WriteLine(" " + recoOfUser.ToString());
            }


            Console.WriteLine("\n###################\n");
            Console.WriteLine("-> Articles\n");
            // Articles
            Console.Write("Id of article to fetch (default is 2111): ");
            idString = Console.ReadLine();
            try
            {
                id = Convert.ToInt32(idString);
            }
            catch
            {
                Console.WriteLine("Using default 2111");
                id = 2111;
            }
            Article article = API.getArticle(id);

            Console.WriteLine(article.ToString());

            Console.Write("\nList of category ids to fetch articles for (commasepareted - default is 1,3): ");
            string         catIds = Console.ReadLine();
            List <decimal> ids    = new List <decimal>();

            if (!string.IsNullOrEmpty(catIds))
            {
                string[] catIdsArray = catIds.Split(',');
                foreach (string catIdString in catIdsArray)
                {
                    try {
                        int catId = Convert.ToInt32(catIdString);
                        ids.Add(catId);
                    }
                    catch {}
                }
            }
            if (ids.Count == 0)
            {
                Console.WriteLine("Using default 1,3");
                ids.Add(1);
                ids.Add(3);
            }
            ListOfArticles listArticlesCategory = API.getArticlesListByCategories(ids);

            foreach (Article articleOfCat in listArticlesCategory.entities)
            {
                Console.WriteLine(" " + articleOfCat.ToString());
            }

            Console.Write("\nId of article page fetch articles of (default is 123): ");
            idString = Console.ReadLine();
            try
            {
                id = Convert.ToInt32(idString);
            }
            catch
            {
                Console.WriteLine("Using default 123");
                id = 123;
            }
            ListOfArticles listArticlesByPage = API.getArticlesListByPage(123);

            Console.WriteLine("Page is " + listArticlesByPage.page.ToString());
            foreach (Article articleOfPage in listArticlesByPage.entities)
            {
                Console.WriteLine(" " + article.ToString());
            }

            Console.WriteLine("\n###################\n");
            Console.WriteLine("-> Pages\n");
            //Pages

            Console.Write("Id of page to fetch (default is 4223): ");
            idString = Console.ReadLine();
            try
            {
                id = Convert.ToInt32(idString);
            }
            catch
            {
                Console.WriteLine("Using default 4223");
                id = 4223;
            }
            Page pageById = API.getPage(id);

            Console.WriteLine(pageById.ToString());

            Console.Write("\nDomain to fetch page of (default is spiegel.de): ");
            string domain = Console.ReadLine();

            if (string.IsNullOrEmpty(domain))
            {
                Console.WriteLine("Using default domain spiegel.de");
                domain = "spiegel.de";
            }
            Page pageByDomain = API.getPage(domain);

            Console.WriteLine(pageByDomain.ToString());


            Console.WriteLine("\n###################\n");
            Console.WriteLine("-> Users\n");
            // Users
            Console.Write("Id of user to fetch (default is 1): ");
            idString = Console.ReadLine();
            try
            {
                id = Convert.ToInt32(idString);
            }
            catch
            {
                Console.WriteLine("Using default 1");
                id = 1;
            }
            User userById = API.getUser(id);

            Console.WriteLine(userById.ToString());

            Console.Write("\nUsername to fetch (default is quotefm): ");
            username = Console.ReadLine();
            if (string.IsNullOrEmpty(username))
            {
                Console.WriteLine("Using default username quotefm");
                username = "******";
            }
            User userByUsername = API.getUser(username);

            Console.WriteLine(userByUsername.ToString());

            Console.WriteLine("\nFollowers of " + username);
            ListOfUsers listUserFollowers = API.getUsersListOfFollowers(username);

            foreach (User follower in listUserFollowers.entities)
            {
                Console.WriteLine(" " + follower.ToString());
            }

            Console.WriteLine("\nFollowings of " + username);
            ListOfUsers listUserFollowings = API.getUsersListOfFollowings(username);

            foreach (User following in listUserFollowings.entities)
            {
                Console.WriteLine(" " + following.ToString());
            }

            Console.WriteLine("Completed... Press enter to close");
            Console.ReadLine();
        }