public async Task CreateFriendshipAsync_WithValidInput_Succeeds()
        {
            const string ScreenName   = "JoeMayo";
            const bool   Follow       = false;
            string       expectedName = "Joe Mayo";

            InitializeTwitterContext <User>(SingleUserResponse);

            User actual = await ctx.CreateFriendshipAsync(ScreenName, Follow);

            Assert.AreEqual(expectedName, actual.Name);
        }
Esempio n. 2
0
        static async Task CreateFriendshipAsync(TwitterContext twitterCtx)
        {
            var user = await twitterCtx.CreateFriendshipAsync("JoeMayo", true);

            if (user != null && user.Status != null)
            {
                Console.WriteLine(
                    "User Name: {0}, Status: {1}",
                    user.Name,
                    user.Status.Text);
            }
        }
        public async Task <ActionResult> SeguirAsync(string ScreenName)
        {
            var auth = new MvcAuthorizer
            {
                CredentialStore = new SessionStateCredentialStore()
            };
            var ctx  = new TwitterContext(auth);
            var user = await ctx.CreateFriendshipAsync(ScreenName, true);

            if (user != null && user.Status != null)
            {
                Debug.WriteLine(
                    "User Name: {0}, Status: {1}, Seguindo: {2}",
                    user.Name,
                    user.Status.Text,
                    user.Following);
            }

            return(RedirectToAction("Seguidores", "StatusDemos"));
        }
Esempio n. 4
0
        private void FollowUsers(List <ulong> usersToFollow)
        {
            var outgoing = _twitterCtx.Friendship.SingleOrDefault(req => req.Type == FriendshipType.Outgoing);

            if (outgoing?.IDInfo?.IDs != null)
            {
                usersToFollow = usersToFollow.Except(outgoing.IDInfo.IDs).ToList();
            }

            if (usersToFollow.Any())
            {
                var users = _twitterCtx.User.Where(u => u.Type == UserType.Lookup && u.UserIdList == string.Join(",", usersToFollow)).ToList();

                foreach (var user in users)
                {
                    var result = _twitterCtx.CreateFriendshipAsync(ulong.Parse(user.UserIDResponse), false).Result;
                    if (result?.Status == null)
                    {
                        _logs.WriteLog($"An error during following. Returned user is null.");
                    }
                }
                _logs.WriteLog($"Followed {usersToFollow.Count()} users");
            }
        }