Example #1
0
        private void Test_SearchTwitterUserByScreenName_ReturnCorrectResults_OrRateLimitedResponse(string twitterScreenName)
        {

            TwitterClient client = new TwitterClient();
            TweetUsers tweetUser = new TweetUsers();

            try
            {
                tweetUser = client.GetUserDetailsByScrapping(twitterScreenName);
                Assert.IsNotNull(tweetUser);
                Assert.AreEqual(tweetUser.ScreenName, twitterScreenName, true);
            }
            catch (Exception ex)
            {
                string twitterLimitException = "The remote server returned an unexpected response: (400) Bad Request.";
                string twitterHttpException = "The HTTP request was forbidden with client authentication scheme 'Basic'.";
                if (ex.Message.Equals(twitterHttpException))
                {
                    Assert.AreEqual(twitterHttpException, ex.Message);
                }
                else
                {
                    Assert.AreEqual(twitterLimitException, ex.Message);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Retrieve the tweet user details from twitter
        /// </summary>
        /// <param name="twitterScreenName"></param>
        /// <returns></returns>
        public TweetUsers RetrieveTweetUserDetails(string twitterScreenName)
        {
             //TODO: Call the twitter api to get the user details
            TwitterClient client;
            TweetUsers tweetUser =  new TweetUsers();
            
            try
            {
                client = new TwitterClient();
                //tweetUser = client.GetUserDetails(twitterScreenName);
                tweetUser = client.GetUserDetailsByScrapping(twitterScreenName); //Temporary fix
            }
            catch (Exception ex)
            {
                InputContext.Diagnostics.WriteExceptionToLog(ex);
                tweetUser.TwitterResponseException = ex;
            }

            return tweetUser;
        }
Example #3
0
        /// <summary>
        /// This method creates and maps the twitter user to a DNA User ID and retrieve the created twitter user details
        /// </summary>
        /// <param name="searchText"></param>
        /// <param name="dataReader"></param>
        private string CreateRetrieveTwitterUser(string searchText, IDnaDataReader dataReader)
        {
            //TODO: Call the twitter api to get the user details
            TwitterClient client;
            TweetUsers tweetUser;
            //var twitterAPIException = string.Empty;
            var twitterException = string.Empty;
            try
            {
                client = new TwitterClient();
                tweetUser = new TweetUsers();

                //tweetUser = client.GetUserDetails(searchText);
                tweetUser = client.GetUserDetailsByScrapping(searchText);

                // Create the twitter user with the associated dnauserid in DNA
                if (tweetUser != null)
                {
                    ICacheManager cacheManager = CacheFactory.GetCacheManager();

                    var callingUser = new CallingTwitterUser(this.readerCreator, this.dnaDiagnostic, cacheManager);

                    //Create the twitter user and map it to DNA with site id 1
                    callingUser.CreateUserFromTwitterUser(1, tweetUser);
                    callingUser.SynchroniseSiteSuffix(tweetUser.ProfileImageUrl);

                    if (dataReader != null)
                    {
                        dataReader.Execute();
                    }
                }
            }
            catch (Exception ex)
            {
                InputContext.Diagnostics.WriteExceptionToLog(ex);

                var twitterRateLimitException = "Rate limit exceeded.";
                var twitterErrorNotFound = "The remote server returned an error: (404) Not Found.";
                var twitterUnexpectedResponseException = "The remote server returned an unexpected response: (400) Bad Request.";

                if (ex.Message.Contains(twitterRateLimitException))
                {
                    twitterException = "Twitter API has reached its rate limit. Please try again later.";
                }
                else if (ex.Message.Equals(twitterErrorNotFound) ||
                    ex.InnerException.Message.Equals(twitterErrorNotFound))
                {
                    twitterException = "Searched user not found in Twitter";
                }
                else if (ex.Message.Equals(twitterUnexpectedResponseException))
                {
                    twitterException = "Twitter Exception: " + ex.Message + " Please try again in few minutes.";
                }
                else
                {
                    twitterException = "Twitter Exception: " + ex.Message;
                }
            }

            return twitterException;
        }
Example #4
0
        public void SearchTwitterUserByScreenName_ReturnInCorrectResults_AlwaysException()
        {
            var strTwitterScreenName = "DotNetTemp";
            TwitterClient client = new TwitterClient();
            TweetUsers tweetUser = new TweetUsers();

            try
            {
                tweetUser = client.GetUserDetails(strTwitterScreenName);
            }
            catch (Exception ex)
            {
                string twitterLimitException = "The remote server returned an unexpected response: (400) Bad Request.";
                string twitterErrorNotFound = "The remote server returned an error: (404) Not Found.";
                string twitterHttpException = "The HTTP request was forbidden with client authentication scheme 'Basic'.";
                string twitterException = "The remote server returned an unexpected response: (410) Gone.";

                if (ex.InnerException.Message.Equals(twitterErrorNotFound))
                {
                    Assert.AreEqual(twitterErrorNotFound, ex.InnerException.Message);
                }
                else if (ex.Message.Equals(twitterHttpException))
                {
                    Assert.AreEqual(twitterHttpException, ex.Message);
                }
                else if(ex.Message.Equals(twitterException))
                {
                    Assert.AreEqual(twitterException, ex.Message);
                }
                else
                {
                    Assert.AreEqual(twitterLimitException, ex.Message);
                }
                return;
            }
            Assert.Fail();
        }