internal async Task LoadLiveTimeline(TwitterClient userClient, IAuthenticatedUser user)
        {
            try
            {
                internalHelpers.DisplayLogo(user);
                Console.WriteLine();
                Console.WriteLine("Retrieving timeline..");

                var homeTimelineTweets = await userClient.Timelines.GetHomeTimelineAsync(new GetHomeTimelineParameters()
                {
                    PageSize = initialPageSize
                });

                Console.WriteLine();
                Console.WriteLine("---------------------------------------------------------".Pastel(colors.seperatorColor));

                ITweet finalTweet = null;

                if (homeTimelineTweets.Length > 0)
                {
                    homeTimelineTweets = homeTimelineTweets.OrderBy(t => t.CreatedAt.UtcDateTime).ToArray();
                    foreach (var tweet in homeTimelineTweets)
                    {
                        internalHelpers.DisplayTweet(tweet);
                        finalTweet = tweet;
                        Thread.Sleep(TimeSpan.FromSeconds(scanDelay));
                    }
                }

                while (true)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(searchDelay));
                    var parameters = new GetHomeTimelineParameters()
                    {
                        SinceId  = finalTweet.Id,
                        PageSize = 1,
                    };

                    var latestTweet = await userClient.Timelines.GetHomeTimelineAsync(parameters);

                    if (latestTweet.Length > 0)
                    {
                        if (latestTweet[0] != finalTweet)
                        {
                            internalHelpers.DisplayTweet(latestTweet.Last());
                            finalTweet = latestTweet.Last();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw;
            }
        }
Beispiel #2
0
        // Home Timeline

        public ITwitterPageIterator <ITwitterResult <ITweetDTO[]>, long?> GetHomeTimelineIterator(IGetHomeTimelineParameters parameters, ITwitterRequest request)
        {
            return(_pageCursorIteratorFactories.Create(parameters, cursor =>
            {
                var cursoredParameters = new GetHomeTimelineParameters(parameters)
                {
                    MaxId = cursor
                };

                return _timelineQueryExecutor.GetHomeTimeline(cursoredParameters, new TwitterRequest(request));
            }));
        }
Beispiel #3
0
        public void GetHomeTimelineIterator_ReturnsFromPageCursorIteratorFactories()
        {
            // arrange
            var parameters = new GetHomeTimelineParameters {
                PageSize = 2
            };
            var request        = A.Fake <ITwitterRequest>();
            var expectedResult = A.Fake <ITwitterPageIterator <ITwitterResult <ITweetDTO[]>, long?> >();

            A.CallTo(() => _fakePageCursorIteratorFactories.Create(parameters, It.IsAny <Func <long?, Task <ITwitterResult <ITweetDTO[]> > > >()))
            .Returns(expectedResult);

            var controller = CreateTimelineController();
            var iterator   = controller.GetHomeTimelineIterator(parameters, request);

            // assert
            Assert.Equal(iterator, expectedResult);
        }
        public async IAsyncEnumerable <StatusUpdate> GetStatusUpdatesAsync()
        {
            var self = await _client.Users.GetAuthenticatedUserAsync();

            var parameters = new GetHomeTimelineParameters {
                PageSize        = 100,
                IncludeEntities = true
            };

            while (true)
            {
                ITweet[] page = await _client.Timelines.GetHomeTimelineAsync(parameters);

                if (!page.Any())
                {
                    break;
                }

                foreach (var t in page)
                {
                    yield return(new StatusUpdate {
                        Host = Host,
                        Id = t.IdStr,
                        CanDelete = t.CreatedBy.Id == self.Id,
                        Author = new Author {
                            Username = t.CreatedBy.ScreenName,
                            AvatarUrl = t.CreatedBy.ProfileImageUrl,
                            ProfileUrl = $"https://twitter.com/{Uri.EscapeDataString(t.CreatedBy.ScreenName)}"
                        },
                        Timestamp = t.CreatedAt,
                        LinkUrl = t.RetweetedTweet?.Url ?? t.Url,
                        Html = WebUtility.HtmlEncode(WebUtility.HtmlDecode(t.FullText ?? t.Text)),
                        AdditionalImages = t.Entities.Medias.Where(m => m.MediaType == "photo").Select(m => new StatusUpdateMedia {
                            ImageUrl = m.MediaURLHttps,
                            LinkUrl = m.URL
                        }).ToList(),
                        RepostedFrom = t.RetweetedTweet?.CreatedBy?.ScreenName
                    });
                }
                parameters.MaxId = page.Select(x => x.Id).Min() - 1;
            }
        }
Beispiel #5
0
        public async Task GetHomeTimelineQuery_ReturnsTweetsAsync()
        {
            // Arrange
            var queryExecutor = CreateTimelineQueryExecutor();
            var expectedQuery = TestHelper.GenerateString();

            var parameters     = new GetHomeTimelineParameters();
            var request        = A.Fake <ITwitterRequest>();
            var expectedResult = A.Fake <ITwitterResult <ITweetDTO[]> >();

            A.CallTo(() => _fakeTimelineQueryGenerator.GetHomeTimelineQuery(parameters, It.IsAny <TweetMode?>())).Returns(expectedQuery);
            A.CallTo(() => _fakeTwitterAccessor.ExecuteRequestAsync <ITweetDTO[]>(request)).Returns(expectedResult);

            // Act
            var result = await queryExecutor.GetHomeTimelineAsync(parameters, request);

            // Assert
            Assert.Equal(result, expectedResult);
            Assert.Equal(request.Query.Url, expectedQuery);
            Assert.Equal(HttpMethod.GET, request.Query.HttpMethod);
        }
        public void GetHomeTimelineQuery_ReturnsExpectedQuery()
        {
            // Arrange
            var queryGenerator = CreateTimelineQueryGenerator();

            var parameters = new GetHomeTimelineParameters
            {
                IncludeEntities       = true,
                TrimUser              = true,
                ExcludeReplies        = true,
                MaxId                 = 42,
                SinceId               = 43,
                PageSize              = 44,
                CustomQueryParameters = { new Tuple <string, string>("hello", "world") }
            };

            // Act
            var result = queryGenerator.GetHomeTimelineQuery(parameters, ComputedTweetMode.Extended);

            // Assert
            Assert.Equal(result, $"https://api.twitter.com/1.1/statuses/home_timeline.json?count=44&since_id=43&max_id=42" +
                         $"&include_entities=true&trim_user=true&tweet_mode=extended&exclude_replies=true&hello=world");
        }