Example #1
0
        /// <summary>
        /// Returns a list of direct messages sent by the autenthicated user, matching the supplied options
        /// </summary>
        /// <param name="statusRequestOptions">Accepted options: SinceID, MaxID, Count, & Page</param>
        /// <returns>List of DirectMessage objects sent by the authenticated user, matching the supplied options</returns>
        public IList<DirectMessage> GetSentDirectMessages(StatusRequestOptions statusRequestOptions)
        {
            string apiURL = "http://twitter.com/direct_messages/sent.xml";
            string responseText = _requestHandler.MakeAPIRequest(_requestHandler, statusRequestOptions.BuildRequestUri(apiURL));

            return ResponseParser.ReturnDirectMsgs(responseText);
        }
Example #2
0
        /// <summary>
        /// Returns list of IDs of every user being followed by the user specified in the supplied options
        /// </summary>
        /// <param name="statusRequestOptions">Accepted options: UserID & ScreenName</param>
        /// <returns>List of UserIDs</returns>
        public IList<long> GetFollowingList(StatusRequestOptions statusRequestOptions)
        {
            string apiURL = "http://twitter.com/friends/ids.xml";
            string responseText = _requestHandler.MakeAPIRequest(_requestHandler, statusRequestOptions.BuildRequestUri(apiURL));

            return ResponseParser.ReturnUserIDs(responseText);
        }
Example #3
0
        /// <summary>
        /// Gets a specific user's timeline
        /// </summary>
        /// <param name="statusRequestOptions">Accepted options: UserId, ScreenName, SinceId, MaxId, Count, & Page</param>
        /// <returns>List of StatusMessage objects of the specific user's statuses, matching the supplied StatusRequestOptions</returns>
        public IList<StatusMessage> GetUserTimeline(StatusRequestOptions statusRequestOptions)
        {
            string apiURL = "http://twitter.com/statuses/user_timeline.xml";
            string responseText = _requestHandler.MakeAPIRequest(_requestHandler, statusRequestOptions.BuildRequestUri(apiURL));

            return ResponseParser.ReturnStatuses(responseText);
        }
Example #4
0
        /// <summary>
        /// Gets a user's friends and their most recent statuses 
        /// Authenticated user by default, use StatusRequestOptions to be more specific.
        /// </summary>
        /// <param name="statusRequestOptions">Accepted options: UserID, ScreenName</param>
        /// <returns>List of Users who the supplied user is following. Requires authentication if supplied user is protected</returns>
        public IList<IUser> GetUsersFriends(StatusRequestOptions statusRequestOptions)
        {
            string apiURL = "http://twitter.com/statuses/friends.xml";
            string resposneText = _requestHandler.MakeAPIRequest(_requestHandler, statusRequestOptions.BuildRequestUri(apiURL));

            return ResponseParser.ReturnUsers(resposneText);
        }
Example #5
0
        public void RequestOptions_Returns_PassedURL()
        {
            string testUrl = "http://twitter.com/statuses/mentions.xml";
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            string builtUrl = statusRequestOptions.BuildRequestUri(testUrl);

            Assert.AreEqual(testUrl, builtUrl);
        }
Example #6
0
        public void RequestOptions_Returns_URLForCount()
        {
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.Count, testCount);
            string builtUrl = statusRequestOptions.BuildRequestUri(testUrl);

            Assert.AreEqual(String.Format("{0}?count={1}", testUrl, testCount), builtUrl);
        }
Example #7
0
        public void GetSingleUser_Test()
        {
            StatusRequestOptions requestOptions = new StatusRequestOptions();
            requestOptions.Add(StatusRequestOptionNames.ScreenName, "mkoby");
            IUser user = twitter.GetSingleUser(requestOptions);

            Assert.IsNotNull(user);
            Assert.AreEqual("mkoby", user.ScreenName);
        }
        public void Get_Mentions_WithCount_Test()
        {
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.Count, 1);

            IList<StatusMessage> mentions = twitter.GetMetions(statusRequestOptions);

            Assert.GreaterOrEqual(1, mentions.Count);
        }
        public void TurnDeviceNotificationsOn_WithUserID_Test()
        {
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.UserID, testUserID);
            IUser userFollowed = twitter.TurnDeviceNotificationsOff(statusRequestOptions);

            Assert.IsNotNull(userFollowed);
            Assert.AreEqual(testUserName, userFollowed.ScreenName);
        }
        public void GetFriendsTimeline_NoArgs_Test()
        {
            StatusRequestOptions myOptions = new StatusRequestOptions();

            IList<StatusMessage> statusList = twitter.GetFriendsTimeline(myOptions);
            Console.WriteLine("Status Count: {0}", statusList.Count);

            Assert.IsNotEmpty((ICollection)statusList,
                              "Status list was empty, expected at least 1 status returned");
        }
        public void GetFollowingList_Test()
        {
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.ScreenName, TestUserName);
            IList<long> friendsList = twitter.GetFollowingList(statusRequestOptions);

            Console.WriteLine("Number of Users Being Followed: {0}", friendsList.Count);

            Assert.IsNotNull(friendsList);
            Assert.GreaterOrEqual(friendsList.Count, 20, "Expected at least 1 follower");
        }
Example #12
0
        /// <summary>
        /// Turn device notifications on for user specified in the options
        /// </summary>
        /// <param name="statusRequestOptions">Accepted options: UserID & ScreenName</param>
        /// <returns>User object representing the user for whom device notifications were turned on</returns>
        public IUser TurnDeviceNotificationsOn(StatusRequestOptions statusRequestOptions)
        {
            IUser output = null;
            string apiURL = "http://twitter.com/notifications/follow.xml";
            string responseText = _requestHandler.MakeAPIRequest(_requestHandler, statusRequestOptions.BuildRequestUri(apiURL));
            IList<IUser> userList = ResponseParser.ReturnUsers(responseText);

            if (userList != null)
                output = userList[0];

            return output;
        }
Example #13
0
        /// <summary>
        /// extended information of a given user and their most recent status..
        /// </summary>
        /// <param name="statusRequestOptions">Accepted options: UserID, ScreenName</param>
        /// <returns>User information and most recent status of requested user</returns>
        public IUser GetSingleUser(StatusRequestOptions statusRequestOptions)
        {
            IUser output = null;
            string apiURL = "http://twitter.com/users/show.xml";
            string responseText = _requestHandler.MakeAPIRequest(_requestHandler, statusRequestOptions.BuildRequestUri(apiURL));
            IList<IUser> userList = ResponseParser.ReturnUsers(responseText);

            if (userList != null)
                output = userList[0];

            return output;
        }
Example #14
0
        /// <summary>
        /// Gets a single direct message, matching the supplied id
        /// </summary>
        /// <param name="id">The id of the direct message to retrieve</param>
        /// <returns>Single DirectMessage object representing the requested direct message</returns>
        public DirectMessage GetSingleDirectMessage(long id)
        {
            if (id < 0)
                throw new TwitterNetException("The ID must be a value greater than zero.");

            DirectMessage output = null;
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.ID, id);
            IList<DirectMessage> dmList = GetDirectMessages(statusRequestOptions);

            if (dmList != null)
                output = dmList[0];

            return output;
        }
Example #15
0
        public void RequestOptions_Returns_Exception_When_Not_UserTimeline_Username()
        {
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.ScreenName, testScreenName);
            bool exceptionCaught = false;

            try
            {
                statusRequestOptions.BuildRequestUri(testUrl);
            }
            catch(Exception twex)
            {
                exceptionCaught = twex.Message.Contains("only available for certain kinds of requests");
            }

            Assert.IsTrue(exceptionCaught);
        }
        public void Get_UserTimeline_longID()
        {
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.UserID, TestUserID);

            IList<StatusMessage> statusList = twitter.GetUserTimeline(statusRequestOptions);

            foreach (var status in statusList)
            {
                Console.WriteLine("{0}: {1}", status.Author.ScreenName, status.MessageText);
            }

            var idCount = from c in statusList
                            where c.Author.ID == TestUserID
                            select c;

            Assert.AreEqual(20, idCount.Count());
        }
        public void GetFriendsTimeline_MaxStatusID_Test()
        {
            Assert.AreNotEqual(long.MinValue, maxTestStatusID, "maxTestStatusID is Long.MinValue");

            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.MaxID, maxTestStatusID);

            IList<StatusMessage> statusList = twitter.GetFriendsTimeline(statusRequestOptions);

            //Make sure we got at least 1 status back
            Assert.IsNotEmpty((ICollection)statusList,
                              "Status list was empty, expected at least 1 status returned");

            //Test to ensure statusID falls where we think it should
            long maxStatusID = statusList.Max(status => status.ID);

            Console.WriteLine("TestStatusID: {0}\nMaxStatusID: {1}", maxTestStatusID, maxStatusID);
            Assert.LessOrEqual(maxStatusID, maxTestStatusID, "MaxStatusID is GREATER than TestStatusID");
        }
        public void Get_UserTimeline_MaxStatusID()
        {
            //We're going to run this for a specific user
            //because the test account doesn't post updates
            //very often and we can't control test-run order
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.ScreenName, TestUserName);
            statusRequestOptions.Add(StatusRequestOptionNames.MaxID, maxTestStatusID);

            IList<StatusMessage> statusList = twitter.GetUserTimeline(statusRequestOptions);

            //Make sure we got at least 1 status back
            Assert.IsNotEmpty((ICollection)statusList, "Status list was empty, expected at least 1 status returned");

            long returnedStatusID = (long)statusList.Max(status => status.ID);

            Console.WriteLine("TestStatusID: {0}\nMaxStatusID: {1}", maxTestStatusID, returnedStatusID);
            Assert.LessOrEqual(returnedStatusID, maxTestStatusID);
        }
        public void GetFriendsTimeline_Page_Test()
        {
            //TODO: Find better method to test than just pull page 2 of tweets
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.Page, 2);
            statusRequestOptions.Add(StatusRequestOptionNames.Count, 7);

            IList<StatusMessage> statusList = twitter.GetFriendsTimeline(statusRequestOptions);

            #region Console

            Console.WriteLine("Statuses from page 2");

            foreach (StatusMessage status in statusList)
            {
                Console.WriteLine("({0}){1}: {2}", status.ID, status.Author.ScreenName, status.MessageText);
            }

            #endregion

            Assert.IsNotEmpty((ICollection)statusList,
                              "Status list was empty, expected at least 1 status returned");
            Assert.AreEqual(7, statusList.Count);
        }
        public void TwitterNET_Tests_Setup()
        {
            //Grab recent status ID
            twitter = new Twitter(String.Empty, String.Empty);

            try
            {
                StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
                statusRequestOptions.Add(StatusRequestOptionNames.ScreenName, "apitest4769");
                IList<StatusMessage> userTimeline = twitter.GetUserTimeline(statusRequestOptions);

                if(userTimeline != null && userTimeline.Count > 0)
                {
                    minTestStatusID = userTimeline.Min(status => status.ID);
                    maxTestStatusID = userTimeline.Max(status => status.ID);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Example #21
0
        public void RequestOptions_Returns_URLForPageNumber()
        {
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.Page, testPage);
            string builtUrl = statusRequestOptions.BuildRequestUri(testUrl);

            Assert.AreEqual(String.Format("{0}?page={1}", testUrl, testPage), builtUrl);
        }
Example #22
0
        public void RequestOptions_Returns_URLForMaxID()
        {
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.MaxID, testStatusID);
            string builtUrl = statusRequestOptions.BuildRequestUri(testUrl);

            Assert.AreEqual(String.Format("{0}?max_id={1}", testUrl, testStatusID), builtUrl);
        }
Example #23
0
        public void RequestOptions_Returns_URLForScreenName()
        {
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.ScreenName, testScreenName);
            string builtUrl = statusRequestOptions.BuildRequestUri(testUserUrl);

            Assert.AreEqual(String.Format("{0}?screen_name={1}", testUserUrl, testScreenName), builtUrl);
        }
        public void TestFixture_Setup()
        {
            try
            {
                twitter = new Twitter("apitest4769", "testaccount");

                //Ensure we're following the user we'll need in some tests
                if (!twitter.CheckFriendship("apitest4769", "mkoby"))
                    twitter.FollowUser("mkoby", false);

                StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
                statusRequestOptions.Add(StatusRequestOptionNames.Page, 3);
                statusRequestOptions.Add(StatusRequestOptionNames.ScreenName, TestUserName);
                IList<StatusMessage> friendsTimeline = twitter.GetUserTimeline(statusRequestOptions);

                if (friendsTimeline != null && friendsTimeline.Count > 0)
                {
                    minTestStatusID = friendsTimeline.Min(status => status.ID);
                    maxTestStatusID = friendsTimeline.Max(status => status.ID);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            twitter = null;
        }
        public void GetFriendsTimeline_ReturnCountOnly_Test()
        {
            StatusRequestOptions statusRequestOptions = new StatusRequestOptions();
            statusRequestOptions.Add(StatusRequestOptionNames.Count, 5);

            IList<StatusMessage> statusList = twitter.GetFriendsTimeline(statusRequestOptions);

            //Make sure we got at least 1 status back
            Assert.IsNotEmpty((ICollection)statusList,
                              "Status list was empty, expected at least 1 status returned");

            #region Console

            //Console printout to compare with online webpage to ensure accuracy in order and recent tweets
            foreach (StatusMessage status in statusList)
            {
                Console.WriteLine("({0}){1}: {2}", status.ID, status.Author.ScreenName, status.MessageText);
            }

            #endregion

            Assert.AreEqual(5, statusList.Count,
                            "Expected 5 statuses only had " + statusList.Count);
        }