/// <summary> /// This method retrieves the authenicated user by creating a query for Twitter. /// /// Precondition: none /// Postcondition: none /// </summary> /// <returns></returns> public UserEntity GetAuthenticatedUser() { TwitterQuery twitterQuery = TwitterQuery.Create(TwitterConstants.AuthUserUrl); twitterQuery.AddParameter("skip_status", "true"); twitterQuery.AddParameter("include_entities", "true"); string result = ExecuteQuery(twitterQuery); UserEntity user = JsonHelper.DeserializeToClass <UserEntity>(result); return(user); }
/// <summary> /// This method is used to retrieve the friend ids from the user by adding the required friend parameters to the query /// /// Precondition: none /// Postcondition: none /// </summary> /// <param name="userId">passed userId value</param> /// <returns>returns the resultIds or a new long[0]</returns> private long[] GetFriendIds(long userId) { var twitterQuery = TwitterQuery.Create(TwitterConstants.FriendIdsUrl); twitterQuery.AddParameter("user_id", userId); twitterQuery.AddParameter("count", TwitterConstants.MaxFriendsToRetrive); string result = ExecuteQuery(twitterQuery); var resultIds = JsonHelper.DeserializeToClass <ResultIds>(result); return(resultIds.Ids ?? new long[0]); }
public void TestAddParamaterWithStringAndDouble() { TwitterQuery q = TwitterQuery.Create("teststring"); q.AddParameter("Keystring", 3.5); List <KeyValuePair <string, string> > l = new List <KeyValuePair <string, string> >(); l.Add(new KeyValuePair <string, string>("Keystring", "3.5")); CollectionAssert.AreEqual(l, q.QueryParameterList); Assert.AreEqual("teststring?Keystring=3.5", q.QueryUrl); }
public void TestAddParamaterTwiceWithInt() { TwitterQuery q = TwitterQuery.Create("teststring"); q.AddParameter("Keystring", 3); q.AddParameter("Keystring2", 4); List <KeyValuePair <string, string> > l = new List <KeyValuePair <string, string> >(); l.Add(new KeyValuePair <string, string>("Keystring", "3")); l.Add(new KeyValuePair <string, string>("Keystring2", "4")); CollectionAssert.AreEqual(l, q.QueryParameterList); Assert.AreEqual("teststring?Keystring=3&Keystring2=4", q.QueryUrl); }
/// <summary> /// The following method retrieves the user's tweet list by adding parameters to the query for Twitter access. /// /// Precondition:none /// Postcondition: none /// </summary> /// <param name="userId">passed userId value</param> /// <param name="count">passed in count value</param> /// <param name="includeRetweet">boolean on choosing to include a retweet</param> /// <returns>tweetList or a brand new TweetEntity List</returns> public List <TweetEntity> GetUserTweetList(long userId, int count, bool includeRetweet = false) { var twitterQuery = TwitterQuery.Create(TwitterConstants.UserTweetsUrl); twitterQuery.AddParameter("user_id", userId); twitterQuery.AddParameter("include_rts", includeRetweet); twitterQuery.AddParameter("exclude_replies", false); twitterQuery.AddParameter("contributor_details", false); twitterQuery.AddParameter("count", count); twitterQuery.AddParameter("trim_user", false); twitterQuery.AddParameter("include_entities", true); twitterQuery.AddParameter("tweet_mode", "extended"); string result = ExecuteQuery(twitterQuery); var tweetList = JsonHelper.DeserializeToClass <List <TweetEntity> >(result); return(tweetList ?? new List <TweetEntity>()); }
/// <summary> /// This method gets the required information for the user friends from the friend ids. /// /// Precondition: checks if friends are null /// Postcondition: add the range of friends to the friendList /// </summary> /// <param name="friendIds">passed in friendIds</param> /// <returns>friendList</returns> private List <UserEntity> GetFriendsFromIds(long[] friendIds) { // Twitter allows only MaxFriendsToLookupPerCall per query, so make multiple calls var friendList = new List <UserEntity>(); for (int index = 0; index < friendIds.Length; index += TwitterConstants.MaxFriendsToLookupPerCall) { var twitterQuery = TwitterQuery.Create(TwitterConstants.UsersDataUrl); var friendIdsToLookup = friendIds.Skip(index).Take(TwitterConstants.MaxFriendsToLookupPerCall).ToArray(); string userIdsParam = GenerateIdsParameter(friendIdsToLookup); twitterQuery.AddParameter("user_id", userIdsParam); string queryResult = ExecuteQuery(twitterQuery); var friends = JsonHelper.DeserializeToClass <List <UserEntity> >(queryResult); if (friends == null) { break; } friendList.AddRange(friends); } return(friendList); }
public void TestCreateWithUrl() { TwitterQuery q = TwitterQuery.Create("https://twitter.com/4600Project"); Assert.AreEqual("https://twitter.com/4600Project", q.QueryUrl); }
public void TestCreateWithString() { TwitterQuery q = TwitterQuery.Create("teststring"); Assert.AreEqual("teststring", q.QueryUrl); }