Ejemplo n.º 1
0
        public string GetSearchTweetsQuery(ITweetSearchParameters tweetSearchParameters)
        {
            if (!_searchQueryValidator.IsSearchParameterValid(tweetSearchParameters))
            {
                return(null);
            }

            var searchQuery = GetQuery(tweetSearchParameters.SearchQuery, tweetSearchParameters.Filters);

            if (!_searchQueryValidator.IsSearchTweetsQueryValid(searchQuery))
            {
                return(null);
            }

            StringBuilder query = new StringBuilder();

            query.Append(_searchQueryParameterGenerator.GenerateSearchQueryParameter(searchQuery));
            query.Append(_searchQueryParameterGenerator.GenerateSearchTypeParameter(tweetSearchParameters.SearchType));

            query.Append(_queryParameterGenerator.GenerateSinceIdParameter(tweetSearchParameters.SinceId));
            query.Append(_queryParameterGenerator.GenerateMaxIdParameter(tweetSearchParameters.MaxId));
            query.Append(_queryParameterGenerator.GenerateCountParameter(tweetSearchParameters.MaximumNumberOfResults));

            query.Append(_searchQueryParameterGenerator.GenerateGeoCodeParameter(tweetSearchParameters.GeoCode));
            query.Append(_searchQueryParameterGenerator.GenerateLangParameter(tweetSearchParameters.Lang));
            query.Append(_searchQueryParameterGenerator.GenerateLocaleParameter(tweetSearchParameters.Locale));
            query.Append(_searchQueryParameterGenerator.GenerateSinceParameter(tweetSearchParameters.Since));
            query.Append(_searchQueryParameterGenerator.GenerateUntilParameter(tweetSearchParameters.Until));
            query.Append(_queryParameterGenerator.GenerateAdditionalRequestParameters(tweetSearchParameters.FormattedCustomQueryParameters));

            return(query.ToString());
        }
Ejemplo n.º 2
0
        private IEnumerable<string> SearchTweetsRecursively(ITweetSearchParameters tweetSearchParameters)
        {
            var searchParameter = _searchQueryHelper.CloneTweetSearchParameters(tweetSearchParameters);
            searchParameter.MaximumNumberOfResults = Math.Min(searchParameter.MaximumNumberOfResults, 100);

            string query = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
            var json = GetJsonResultFromQuery(query);
            var jsonResult = new List<string> { json };
            var currentResult = _searchQueryHelper.GetTweetsFromJsonResponse(json);
            List<ITweetDTO> tweetDTOResult = currentResult;

            while (tweetDTOResult.Count < tweetSearchParameters.MaximumNumberOfResults)
            {
                if (currentResult.IsEmpty())
                {
                    // If Twitter does not any result left, stop the search
                    break;
                }

                var oldestTweetId = _tweetHelper.GetOldestTweetId(currentResult);
                searchParameter.MaxId = oldestTweetId - 1;

                searchParameter.MaximumNumberOfResults = Math.Min(tweetSearchParameters.MaximumNumberOfResults - tweetDTOResult.Count, 100);
                query = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
                
                json = GetJsonResultFromQuery(query);
                jsonResult.Add(json);

                currentResult = _searchQueryHelper.GetTweetsFromJsonResponse(json);
                tweetDTOResult.AddRange(currentResult);
            }

            return jsonResult;
        }
Ejemplo n.º 3
0
        public IEnumerable <ISearchResultsDTO> SearchTweetsWithMetadata(ITweetSearchParameters tweetSearchParameters)
        {
            if (tweetSearchParameters == null)
            {
                throw new ArgumentException("TweetSearch Parameters cannot be null");
            }

            List <ISearchResultsDTO> result = new List <ISearchResultsDTO>();;

            if (tweetSearchParameters.MaximumNumberOfResults > 100)
            {
                result = SearchTweetsRecursively(tweetSearchParameters);
            }
            else
            {
                string httpQuery = _searchQueryGenerator.GetSearchTweetsQuery(tweetSearchParameters);

                var searchTweetResult = GetSearchTweetResultsFromQuery(httpQuery);
                if (searchTweetResult == null)
                {
                    return(null);
                }

                result.Add(searchTweetResult);
            }

            UpdateMatchingTweets(result, tweetSearchParameters);

            return(result);
        }
        public IEnumerable <ITweetDTO> SearchTweets(ITweetSearchParameters tweetSearchParameters)
        {
            if (tweetSearchParameters == null)
            {
                throw new ArgumentException("TweetSearch Parameters cannot be null");
            }

            IEnumerable <ITweetDTO> result;

            if (tweetSearchParameters.MaximumNumberOfResults > 100)
            {
                result = SearchTweetsRecursively(tweetSearchParameters);
            }
            else
            {
                string httpQuery = _searchQueryGenerator.GetSearchTweetsQuery(tweetSearchParameters);
                result = GetTweetDTOsFromSearch(httpQuery);
            }

            if (tweetSearchParameters.TweetSearchFilter == TweetSearchFilter.OriginalTweetsOnly)
            {
                return(result.Where(x => x.RetweetedTweetDTO == null));
            }

            if (tweetSearchParameters.TweetSearchFilter == TweetSearchFilter.RetweetsOnly)
            {
                return(result.Where(x => x.RetweetedTweetDTO != null));
            }

            return(result);
        }
Ejemplo n.º 5
0
        private IEnumerable <ITweetDTO> SearchTweetsRecursively(ITweetSearchParameters tweetSearchParameters)
        {
            var searchParameter = CloneTweetSearchParameters(tweetSearchParameters);

            searchParameter.MaximumNumberOfResults = Math.Min(searchParameter.MaximumNumberOfResults, 100);

            string           httpQuery     = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
            var              currentResult = GetTweetDTOsFromSearch(httpQuery);
            List <ITweetDTO> result        = currentResult;

            while (result.Count < tweetSearchParameters.MaximumNumberOfResults)
            {
                var oldestTweetId = GetOldestTweetId(currentResult);
                searchParameter.MaxId = oldestTweetId;
                searchParameter.MaximumNumberOfResults = Math.Min(tweetSearchParameters.MaximumNumberOfResults - result.Count, 100);
                httpQuery     = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
                currentResult = GetTweetDTOsFromSearch(httpQuery);
                result.AddRange(currentResult);

                if (currentResult.Count < searchParameter.MaximumNumberOfResults)
                {
                    // There is no other result
                    break;
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
        public IEnumerable<ISearchResultsDTO> SearchTweetsWithMetadata(ITweetSearchParameters tweetSearchParameters)
        {
            if (tweetSearchParameters == null)
            {
                throw new ArgumentException("TweetSearch Parameters cannot be null");
            }

            List<ISearchResultsDTO> result =  new List<ISearchResultsDTO>();;
            if (tweetSearchParameters.MaximumNumberOfResults > 100)
            {
                result = SearchTweetsRecursively(tweetSearchParameters);
            }
            else
            {
                string httpQuery = _searchQueryGenerator.GetSearchTweetsQuery(tweetSearchParameters);
                
                var searchTweetResult = GetSearchTweetResultsFromQuery(httpQuery);
                if (searchTweetResult == null)
                {
                    return null;
                }

                result.Add(searchTweetResult);
            }

            UpdateMatchingTweets(result, tweetSearchParameters);

            return result;
        }
        private IEnumerable <ITweetDTO> SearchTweetsRecursively(ITweetSearchParameters tweetSearchParameters)
        {
            var searchParameter = _searchQueryHelper.CloneTweetSearchParameters(tweetSearchParameters);

            searchParameter.MaximumNumberOfResults = Math.Min(searchParameter.MaximumNumberOfResults, 100);

            string           query         = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
            var              currentResult = GetTweetDTOsFromSearch(query);
            List <ITweetDTO> result        = currentResult;

            while (result.Count < tweetSearchParameters.MaximumNumberOfResults)
            {
                if (currentResult.IsEmpty())
                {
                    // If Twitter does not any result left, stop the search
                    break;
                }

                var oldestTweetId = _tweetHelper.GetOldestTweetId(currentResult);
                searchParameter.MaxId = oldestTweetId;
                searchParameter.MaximumNumberOfResults = Math.Min(tweetSearchParameters.MaximumNumberOfResults - result.Count, 100);
                query         = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
                currentResult = GetTweetDTOsFromSearch(query);
                result.AddRange(currentResult);
            }

            return(result);
        }
Ejemplo n.º 8
0
        public string GetSearchTweetsQuery(ITweetSearchParameters tweetSearchParameters)
        {
            if (!_searchQueryValidator.IsSearchParameterValid(tweetSearchParameters))
            {
                return null;
            }

            var searchQuery = GetQuery(tweetSearchParameters.SearchQuery, tweetSearchParameters.Filters);
            if (!_searchQueryValidator.IsSearchTweetsQueryValid(searchQuery))
            {
                return null;
            }

            StringBuilder query = new StringBuilder();

            query.Append(_searchQueryParameterGenerator.GenerateSearchQueryParameter(searchQuery));
            query.Append(_searchQueryParameterGenerator.GenerateSearchTypeParameter(tweetSearchParameters.SearchType));

            query.Append(_queryParameterGenerator.GenerateSinceIdParameter(tweetSearchParameters.SinceId));
            query.Append(_queryParameterGenerator.GenerateMaxIdParameter(tweetSearchParameters.MaxId));
            query.Append(_queryParameterGenerator.GenerateCountParameter(tweetSearchParameters.MaximumNumberOfResults));

            query.Append(_searchQueryParameterGenerator.GenerateGeoCodeParameter(tweetSearchParameters.GeoCode));
            query.Append(_searchQueryParameterGenerator.GenerateLangParameter(tweetSearchParameters.Lang));
            query.Append(_searchQueryParameterGenerator.GenerateLocaleParameter(tweetSearchParameters.Locale));
            query.Append(_searchQueryParameterGenerator.GenerateSinceParameter(tweetSearchParameters.Since));
            query.Append(_searchQueryParameterGenerator.GenerateUntilParameter(tweetSearchParameters.Until));
            query.Append(_queryParameterGenerator.GenerateAdditionalRequestParameters(tweetSearchParameters.FormattedCustomQueryParameters));

            return query.ToString();
        }
Ejemplo n.º 9
0
        private bool IsAtLeasOneRequiredCriteriaSet(ITweetSearchParameters searchParameters)
        {
            bool isSearchQuerySet   = !String.IsNullOrEmpty(searchParameters.SearchQuery);
            bool isSearchQueryValid = IsSearchQueryValid(searchParameters.SearchQuery);
            bool isGeoCodeSet       = IsGeoCodeValid(searchParameters.GeoCode);

            return((isSearchQuerySet && isSearchQueryValid) || isGeoCodeSet);
        }
        private bool IsAtLeasOneRequiredCriteriaSet(ITweetSearchParameters searchParameters)
        {
            bool isSearchQuerySet = !String.IsNullOrEmpty(searchParameters.SearchQuery);
            bool isSearchQueryValid = IsSearchTweetsQueryValid(searchParameters.SearchQuery);
            bool isGeoCodeSet = IsGeoCodeValid(searchParameters.GeoCode);
            bool isEntitiesTypeSet = searchParameters.Filters != TweetSearchFilters.None;

            return (isSearchQuerySet && isSearchQueryValid) || isGeoCodeSet || isEntitiesTypeSet;
        }
Ejemplo n.º 11
0
        public IEnumerable<ITweetDTO> SearchTweets(ITweetSearchParameters tweetSearchParameters)
        {
            var searchResults = SearchTweetsWithMetadata(tweetSearchParameters);
            if (searchResults == null)
            {
                return null;
            }

            return searchResults.SelectMany(x => x.MatchingTweetDTOs);
        }
 public IEnumerable<string> SearchTweets(ITweetSearchParameters tweetSearchParameters)
 {
     if (tweetSearchParameters.MaximumNumberOfResults > 100)
     {
         return SearchTweetsRecursively(tweetSearchParameters);
     }
     
     string query = _searchQueryGenerator.GetSearchTweetsQuery(tweetSearchParameters);
     return new[] { GetJsonResultFromQuery(query) };
 }
Ejemplo n.º 13
0
        public string GetSearchTweetsQuery(ITweetSearchParameters tweetSearchParameters)
        {
            if (tweetSearchParameters == null ||
                !_searchQueryValidator.IsSearchParameterValid(tweetSearchParameters) ||
                !_searchQueryValidator.IsSearchQueryValid(tweetSearchParameters.SearchQuery))
            {
                return(null);
            }

            var           formattedQuery = _twitterStringFormatter.TwitterEncode(tweetSearchParameters.SearchQuery);
            StringBuilder query          = new StringBuilder(String.Format(Resources.Search_SearchTweets, formattedQuery));

            query.Append(String.Format(Resources.SearchParameter_ResultType, tweetSearchParameters.SearchType));

            if (_searchQueryValidator.IsGeoCodeValid(tweetSearchParameters.GeoCode))
            {
                string latitude  = tweetSearchParameters.GeoCode.Coordinates.Latitude.ToString(CultureInfo.InvariantCulture);
                string longitude = tweetSearchParameters.GeoCode.Coordinates.Longitude.ToString(CultureInfo.InvariantCulture);
                string radius    = tweetSearchParameters.GeoCode.Radius.ToString(CultureInfo.InvariantCulture);
                string measure   = tweetSearchParameters.GeoCode.DistanceMeasure == DistanceMeasure.Kilometers ? "km" : "mi";
                query.Append(String.Format(Resources.SearchParameter_GeoCode, latitude, longitude, radius, measure, CultureInfo.InvariantCulture));
            }

            if (_searchQueryValidator.IsLangDefined(tweetSearchParameters.Lang))
            {
                query.Append(String.Format(Resources.SearchParameter_Lang, tweetSearchParameters.Lang.GetDescriptionAttribute()));
            }

            if (_searchQueryValidator.IsLocaleParameterValid(tweetSearchParameters.Locale))
            {
                query.Append(String.Format(tweetSearchParameters.Locale));
            }

            if (_searchQueryValidator.IsSinceIdDefined(tweetSearchParameters.SinceId))
            {
                query.Append(String.Format(Resources.QueryParameter_SinceId, tweetSearchParameters.SinceId));
            }

            if (_searchQueryValidator.IsMaxIdDefined(tweetSearchParameters.MaxId))
            {
                query.Append(String.Format(Resources.QueryParameter_MaxId, tweetSearchParameters.MaxId));
            }

            if (_searchQueryValidator.IsMaximumNumberOfResultsDefined(tweetSearchParameters.MaximumNumberOfResults))
            {
                query.Append(String.Format(Resources.QueryParameter_Count, tweetSearchParameters.MaximumNumberOfResults));
            }

            if (_searchQueryValidator.IsUntilDefined(tweetSearchParameters.Until))
            {
                query.Append(String.Format(Resources.SearchParameter_Until, tweetSearchParameters.Until.ToString("yyyy-MM-dd")));
            }

            return(query.ToString());
        }
Ejemplo n.º 14
0
        public IEnumerable <ITweetDTO> SearchTweets(ITweetSearchParameters tweetSearchParameters)
        {
            var searchResults = SearchTweetsWithMetadata(tweetSearchParameters);

            if (searchResults == null)
            {
                return(null);
            }

            return(searchResults.SelectMany(x => x.MatchingTweetDTOs));
        }
        public IEnumerable <string> SearchTweets(ITweetSearchParameters tweetSearchParameters)
        {
            if (tweetSearchParameters.MaximumNumberOfResults > 100)
            {
                return(SearchTweetsRecursively(tweetSearchParameters));
            }

            string query = _searchQueryGenerator.GetSearchTweetsQuery(tweetSearchParameters);

            return(new[] { GetJsonResultFromQuery(query) });
        }
Ejemplo n.º 16
0
        public List <ITweet> SearchTweetsEx(string tagName)
        {
            ITweetSearchParameters searchParameter = Search.GenerateTweetSearchParameter(tagName);

            //searchParameter.SetGeoCode(-122.398720, 37.781157, 1, DistanceMeasure.Miles);
            //searchParameter.Lang = Language.English;
            //searchParameter.SearchType = SearchResultType.Popular;
            searchParameter.MaximumNumberOfResults = 100;
            //searchParameter.Until = new DateTime(2013, 12, 1);
            //searchParameter.SinceId = 399616835892781056;
            //searchParameter.MaxId = 405001488843284480;

            return(Search.SearchTweets(searchParameter).ToList());
        }
Ejemplo n.º 17
0
        private List <ISearchResultsDTO> SearchTweetsRecursively(ITweetSearchParameters tweetSearchParameters)
        {
            var searchParameter = _searchQueryHelper.CloneTweetSearchParameters(tweetSearchParameters);

            searchParameter.MaximumNumberOfResults = Math.Min(searchParameter.MaximumNumberOfResults, 100);

            string query = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);

            var currentResult = GetSearchTweetResultsFromQuery(query);

            if (currentResult == null)
            {
                return(new List <ISearchResultsDTO>());
            }

            var result = new List <ISearchResultsDTO> {
                currentResult
            };
            var tweets      = currentResult.TweetDTOs;
            var totalTweets = currentResult.TweetDTOs.ToList();

            while (totalTweets.Count < tweetSearchParameters.MaximumNumberOfResults)
            {
                if (tweets.IsEmpty())
                {
                    // If Twitter does not have any result left, stop the search
                    break;
                }

                var oldestTweetId = _tweetHelper.GetOldestTweetId(tweets);
                searchParameter.MaxId = oldestTweetId - 1;
                searchParameter.MaximumNumberOfResults = Math.Min(tweetSearchParameters.MaximumNumberOfResults - totalTweets.Count, 100);
                query         = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
                currentResult = GetSearchTweetResultsFromQuery(query);

                if (currentResult == null)
                {
                    break;
                }

                tweets = currentResult.TweetDTOs;
                totalTweets.AddRange(tweets);
                result.Add(currentResult);
            }

            return(result);
        }
Ejemplo n.º 18
0
        private ITweetSearchParameters CloneTweetSearchParameters(ITweetSearchParameters tweetSearchParameters)
        {
            var clone = _tweetSearchParameterUnityFactory.Create();

            clone.GeoCode                = tweetSearchParameters.GeoCode;
            clone.Lang                   = tweetSearchParameters.Lang;
            clone.Locale                 = tweetSearchParameters.Locale;
            clone.MaxId                  = tweetSearchParameters.MaxId;
            clone.SearchType             = tweetSearchParameters.SearchType;
            clone.MaximumNumberOfResults = tweetSearchParameters.MaximumNumberOfResults;
            clone.SearchQuery            = tweetSearchParameters.SearchQuery;
            clone.SinceId                = tweetSearchParameters.SinceId;
            clone.TweetSearchFilter      = tweetSearchParameters.TweetSearchFilter;
            clone.Until                  = tweetSearchParameters.Until;

            return(clone);
        }
Ejemplo n.º 19
0
        private IEnumerable <string> SearchTweetsRecursively(ITweetSearchParameters tweetSearchParameters)
        {
            var searchParameter = _searchQueryHelper.CloneTweetSearchParameters(tweetSearchParameters);

            searchParameter.MaximumNumberOfResults = Math.Min(searchParameter.MaximumNumberOfResults, 100);

            string query      = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
            var    json       = GetJsonResultFromQuery(query);
            var    jsonResult = new List <string> {
                json
            };
            var currentResult  = _searchQueryHelper.GetTweetsFromJsonResponse(json);
            var tweetDTOResult = currentResult;

            if (tweetDTOResult == null)
            {
                return(jsonResult);
            }

            while (tweetDTOResult.Count < tweetSearchParameters.MaximumNumberOfResults)
            {
                if (currentResult.IsNullOrEmpty())
                {
                    // If Twitter does not any result left, stop the search
                    break;
                }

                var oldestTweetId = _tweetHelper.GetOldestTweetId(currentResult);
                searchParameter.MaxId = oldestTweetId - 1;

                searchParameter.MaximumNumberOfResults = Math.Min(tweetSearchParameters.MaximumNumberOfResults - tweetDTOResult.Count, 100);
                query = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);

                json = GetJsonResultFromQuery(query);

                if (json != null)
                {
                    jsonResult.Add(json);
                }

                currentResult = _searchQueryHelper.GetTweetsFromJsonResponse(json);
                tweetDTOResult.AddRangeSafely(currentResult);
            }

            return(jsonResult);
        }
Ejemplo n.º 20
0
        private void InitData()
        {
            _searchQuery          = TestHelper.GenerateString();
            _searchQueryParameter = TestHelper.GenerateString();

            _searchResultType    = SearchResultType.Mixed;
            _searchTypeParameter = TestHelper.GenerateString();

            _maximumNumberOfResults          = TestHelper.GenerateRandomInt();
            _maximumNumberOfResultsParameter = TestHelper.GenerateString();

            _sinceId          = TestHelper.GenerateRandomLong();
            _sinceIdParameter = TestHelper.GenerateString();

            _maxId          = TestHelper.GenerateRandomLong();
            _maxIdParameter = TestHelper.GenerateString();

            _since          = DateTime.Now.AddMinutes(TestHelper.GenerateRandomInt());
            _sinceParameter = TestHelper.GenerateString();

            _until          = DateTime.Now.AddMinutes(TestHelper.GenerateRandomInt());
            _untilParameter = TestHelper.GenerateString();

            _locale          = TestHelper.GenerateString();
            _localeParameter = TestHelper.GenerateString();

            _lang = Language.Afrikaans;
            _languageParameter = TestHelper.GenerateString();

            _geoCode          = A.Fake <IGeoCode>();
            _geoCodeParameter = TestHelper.GenerateString();

            _tweetSearchParameters                        = A.Fake <ITweetSearchParameters>();
            _tweetSearchParameters.SearchQuery            = _searchQuery;
            _tweetSearchParameters.SearchType             = _searchResultType;
            _tweetSearchParameters.MaximumNumberOfResults = _maximumNumberOfResults;
            _tweetSearchParameters.SinceId                = _sinceId;
            _tweetSearchParameters.MaxId                  = _maxId;
            _tweetSearchParameters.Since                  = _since;
            _tweetSearchParameters.Until                  = _until;
            _tweetSearchParameters.Locale                 = _locale;
            _tweetSearchParameters.Lang                   = _lang;
            _tweetSearchParameters.GeoCode                = _geoCode;
        }
Ejemplo n.º 21
0
        public ITweetSearchParameters CloneTweetSearchParameters(ITweetSearchParameters tweetSearchParameters)
        {
            var clone = new TweetSearchParameters(tweetSearchParameters.SearchQuery)
            {
                Filters = tweetSearchParameters.Filters,
                GeoCode = tweetSearchParameters.GeoCode,
                Lang    = tweetSearchParameters.Lang,
                Locale  = tweetSearchParameters.Locale,
                MaxId   = tweetSearchParameters.MaxId,
                MaximumNumberOfResults = tweetSearchParameters.MaximumNumberOfResults,
                SearchType             = tweetSearchParameters.SearchType,
                Since           = tweetSearchParameters.Since,
                SinceId         = tweetSearchParameters.SinceId,
                TweetSearchType = tweetSearchParameters.TweetSearchType,
                Until           = tweetSearchParameters.Until
            };

            return(clone);
        }
        public ITweetSearchParameters CloneTweetSearchParameters(ITweetSearchParameters tweetSearchParameters)
        {
            var clone = new TweetSearchParameters(tweetSearchParameters.SearchQuery)
            {
                Filters = tweetSearchParameters.Filters,
                GeoCode = tweetSearchParameters.GeoCode,
                Lang = tweetSearchParameters.Lang,
                Locale = tweetSearchParameters.Locale,
                MaxId = tweetSearchParameters.MaxId,
                MaximumNumberOfResults = tweetSearchParameters.MaximumNumberOfResults,
                SearchType = tweetSearchParameters.SearchType,
                Since = tweetSearchParameters.Since,
                SinceId = tweetSearchParameters.SinceId,
                TweetSearchType = tweetSearchParameters.TweetSearchType,
                Until = tweetSearchParameters.Until
            };

            return clone;
        }
        public void TestInitialize()
        {
            _fakeBuilder = new FakeClassBuilder<SearchQueryExecutor>();
            _fakeSearchQueryGenerator = _fakeBuilder.GetFake<ISearchQueryGenerator>();
            _fakeSearchQueryHelper = _fakeBuilder.GetFake<ISearchQueryHelper>();
            _fakeTwitterAccessor = _fakeBuilder.GetFake<ITwitterAccessor>();
            _fakeTweetHelper = _fakeBuilder.GetFake<ITweetHelper>();
            _fakeSearchQueryParameterGenerator = _fakeBuilder.GetFake<ISearchQueryParameterGenerator>();

            _searchQuery = TestHelper.GenerateString();
            _httpQuery = TestHelper.GenerateString();
            _statusesJson = TestHelper.GenerateString();
            _originalTweetDTO = GenerateTweetDTO(true);
            _retweetDTO = GenerateTweetDTO(false);

            _jObject = new JObject();
            _jObject["statuses"] = _statusesJson;
            _tweetDTOs = new[] { A.Fake<ITweetWithSearchMetadataDTO>() };
            _searchResultDTO = A.Fake<ISearchResultsDTO>();
            _searchResultDTO.CallsTo(x => x.TweetDTOs).Returns(_tweetDTOs);

            _tweetSearchParameter = A.Fake<ITweetSearchParameters>();
            _fakeSearchQueryParameterGenerator.CallsTo(x => x.CreateSearchTweetParameter(_searchQuery)).Returns(_tweetSearchParameter);
        }
Ejemplo n.º 24
0
        public void TestInitialize()
        {
            _fakeBuilder = new FakeClassBuilder <SearchQueryExecutor>();
            _fakeSearchQueryGenerator          = _fakeBuilder.GetFake <ISearchQueryGenerator>();
            _fakeSearchQueryHelper             = _fakeBuilder.GetFake <ISearchQueryHelper>();
            _fakeTwitterAccessor               = _fakeBuilder.GetFake <ITwitterAccessor>();
            _fakeTweetHelper                   = _fakeBuilder.GetFake <ITweetHelper>();
            _fakeSearchQueryParameterGenerator = _fakeBuilder.GetFake <ISearchQueryParameterGenerator>();

            _searchQuery      = TestHelper.GenerateString();
            _httpQuery        = TestHelper.GenerateString();
            _statusesJson     = TestHelper.GenerateString();
            _originalTweetDTO = GenerateTweetDTO(true);
            _retweetDTO       = GenerateTweetDTO(false);

            _jObject             = new JObject();
            _jObject["statuses"] = _statusesJson;
            _tweetDTOs           = new[] { A.Fake <ITweetWithSearchMetadataDTO>() };
            _searchResultDTO     = A.Fake <ISearchResultsDTO>();
            _searchResultDTO.CallsTo(x => x.TweetDTOs).Returns(_tweetDTOs);

            _tweetSearchParameter = A.Fake <ITweetSearchParameters>();
            _fakeSearchQueryParameterGenerator.CallsTo(x => x.CreateSearchTweetParameter(_searchQuery)).Returns(_tweetSearchParameter);
        }
Ejemplo n.º 25
0
 public ISearchResult SearchTweetsWithMetadata(ITweetSearchParameters tweetSearchParameters)
 {
     var searchResultsDTO = _searchQueryExecutor.SearchTweetsWithMetadata(tweetSearchParameters).ToArray();
     return _searchResultFactory.Create(searchResultsDTO);
 }
Ejemplo n.º 26
0
        private List<ISearchResultsDTO> SearchTweetsRecursively(ITweetSearchParameters tweetSearchParameters)
        {
            var searchParameter = _searchQueryHelper.CloneTweetSearchParameters(tweetSearchParameters);
            searchParameter.MaximumNumberOfResults = Math.Min(searchParameter.MaximumNumberOfResults, 100);

            string query = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
            
            var currentResult = GetSearchTweetResultsFromQuery(query);
            if (currentResult == null)
            {
                return new List<ISearchResultsDTO>();
            }

            var result = new List<ISearchResultsDTO> { currentResult };
            var tweets = currentResult.TweetDTOs;
            var totalTweets = currentResult.TweetDTOs.ToList();

            while (totalTweets.Count < tweetSearchParameters.MaximumNumberOfResults)
            {
                if (tweets.IsEmpty())
                {
                    // If Twitter does not have any result left, stop the search
                    break;
                }

                var oldestTweetId = _tweetHelper.GetOldestTweetId(tweets);
                searchParameter.MaxId = oldestTweetId - 1;
                searchParameter.MaximumNumberOfResults = Math.Min(tweetSearchParameters.MaximumNumberOfResults - totalTweets.Count, 100);
                query = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
                currentResult = GetSearchTweetResultsFromQuery(query);

                if (currentResult == null)
                {
                    break;
                }

                tweets = currentResult.TweetDTOs;
                totalTweets.AddRange(tweets);
                result.Add(currentResult);
            }

            return result;
        }
Ejemplo n.º 27
0
 public static async Task<IEnumerable<ITweet>> SearchTweets(ITweetSearchParameters tweetSearchParameters)
 {
     return  await Sync.ExecuteTaskAsync(() => Search.SearchTweets(tweetSearchParameters));
 }
Ejemplo n.º 28
0
        public ISearchResult SearchTweetsWithMetadata(ITweetSearchParameters tweetSearchParameters)
        {
            var searchResultsDTO = _searchQueryExecutor.SearchTweetsWithMetadata(tweetSearchParameters).ToArray();

            return(_searchResultFactory.Create(searchResultsDTO));
        }
Ejemplo n.º 29
0
        private void UpdateMatchingTweets(IEnumerable<ISearchResultsDTO> searchResultsDTOs, ITweetSearchParameters tweetSearchParameters)
        {
            foreach (var searchResultsDTO in searchResultsDTOs)
            {
                var tweetDTOs = searchResultsDTO.TweetDTOs;
                if (tweetSearchParameters.TweetSearchType == TweetSearchType.OriginalTweetsOnly)
                {
                    searchResultsDTO.MatchingTweetDTOs = tweetDTOs.Where(x => x.RetweetedTweetDTO == null).ToArray();
                }

                if (tweetSearchParameters.TweetSearchType == TweetSearchType.RetweetsOnly)
                {
                    searchResultsDTO.MatchingTweetDTOs = tweetDTOs.Where(x => x.RetweetedTweetDTO != null).ToArray();
                }

                if (tweetSearchParameters.TweetSearchType == TweetSearchType.All)
                {
                    searchResultsDTO.MatchingTweetDTOs = tweetDTOs;
                }
            }
        }
Ejemplo n.º 30
0
        public IEnumerable <ITweet> SearchTweets(ITweetSearchParameters tweetSearchParameters)
        {
            var tweetsDTO = _searchQueryExecutor.SearchTweets(tweetSearchParameters);

            return(_tweetFactory.GenerateTweetsFromDTO(tweetsDTO));
        }
Ejemplo n.º 31
0
 /// <summary>
 /// Search tweets based on multiple parameters.
 /// </summary>
 /// <returns>This can returns a collection of json responses when the MaximumNumberOfResults parameter is bigger than 100</returns>
 public static IEnumerable<string> SearchTweets(ITweetSearchParameters tweetSearchParameters)
 {
     return SearchJsonController.SearchTweets(tweetSearchParameters);
 }
Ejemplo n.º 32
0
        public string SearchTweets(ITweetSearchParameters tweetSearchParameters)
        {
            string query = _searchQueryGenerator.GetSearchTweetsQuery(tweetSearchParameters);

            return(_twitterAccessor.ExecuteJsonGETQuery(query));
        }
Ejemplo n.º 33
0
 public bool IsSearchParameterValid(ITweetSearchParameters searchParameters)
 {
     return(searchParameters != null && IsAtLeasOneRequiredCriteriaSet(searchParameters));
 }
Ejemplo n.º 34
0
        private void UpdateMatchingTweets(IEnumerable <ISearchResultsDTO> searchResultsDTOs, ITweetSearchParameters tweetSearchParameters)
        {
            foreach (var searchResultsDTO in searchResultsDTOs)
            {
                var tweetDTOs = searchResultsDTO.TweetDTOs;
                if (tweetSearchParameters.TweetSearchType == TweetSearchType.OriginalTweetsOnly)
                {
                    searchResultsDTO.MatchingTweetDTOs = tweetDTOs.Where(x => x.RetweetedTweetDTO == null).ToArray();
                }

                if (tweetSearchParameters.TweetSearchType == TweetSearchType.RetweetsOnly)
                {
                    searchResultsDTO.MatchingTweetDTOs = tweetDTOs.Where(x => x.RetweetedTweetDTO != null).ToArray();
                }

                if (tweetSearchParameters.TweetSearchType == TweetSearchType.All)
                {
                    searchResultsDTO.MatchingTweetDTOs = tweetDTOs;
                }
            }
        }
Ejemplo n.º 35
0
 public static List <ITweet> SearchTweets(ITweetSearchParameters tweetSearchParameters)
 {
     return(SearchController.SearchTweets(tweetSearchParameters).ToList());
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Search tweets with some additional metadata information
 /// </summary>
 public static ISearchResult SearchTweetsWithMetadata(ITweetSearchParameters tweetSearchParameters)
 {
     return(SearchController.SearchTweetsWithMetadata(tweetSearchParameters));
 }
Ejemplo n.º 37
0
 public static async Task <IEnumerable <ITweet> > SearchTweets(ITweetSearchParameters tweetSearchParameters)
 {
     return(await Sync.ExecuteTaskAsync(() => Search.SearchTweets(tweetSearchParameters)));
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Search tweets based on multiple parameters.
 /// </summary>
 /// <returns>This can returns a collection of json responses when the MaximumNumberOfResults parameter is bigger than 100</returns>
 public static IEnumerable <string> SearchTweets(ITweetSearchParameters tweetSearchParameters)
 {
     return(SearchJsonController.SearchTweets(tweetSearchParameters));
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Search tweets based on multiple parameters
 /// </summary>
 public static IEnumerable <ITweet> SearchTweets(ITweetSearchParameters tweetSearchParameters)
 {
     return(SearchController.SearchTweets(tweetSearchParameters));
 }
Ejemplo n.º 40
0
 public IEnumerable<ITweet> SearchTweets(ITweetSearchParameters tweetSearchParameters)
 {
     var tweetsDTO = _searchQueryExecutor.SearchTweets(tweetSearchParameters);
     return _tweetFactory.GenerateTweetsFromDTO(tweetsDTO);
 }
        private void InitData()
        {
            _searchQuery = TestHelper.GenerateString();
            _searchQueryParameter = TestHelper.GenerateString();

            _searchResultType = SearchResultType.Mixed;
            _searchTypeParameter = TestHelper.GenerateString();

            _maximumNumberOfResults = TestHelper.GenerateRandomInt();
            _maximumNumberOfResultsParameter = TestHelper.GenerateString();

            _sinceId = TestHelper.GenerateRandomLong();
            _sinceIdParameter = TestHelper.GenerateString();

            _maxId = TestHelper.GenerateRandomLong();
            _maxIdParameter = TestHelper.GenerateString();

            _since = DateTime.Now.AddMinutes(TestHelper.GenerateRandomInt());
            _sinceParameter = TestHelper.GenerateString();

            _until = DateTime.Now.AddMinutes(TestHelper.GenerateRandomInt());
            _untilParameter = TestHelper.GenerateString();

            _locale = TestHelper.GenerateString();
            _localeParameter = TestHelper.GenerateString();

            _lang = Language.Afrikaans;
            _languageParameter = TestHelper.GenerateString();

            _geoCode = A.Fake<IGeoCode>();
            _geoCodeParameter = TestHelper.GenerateString();

            _tweetSearchParameters = A.Fake<ITweetSearchParameters>();
            _tweetSearchParameters.SearchQuery = _searchQuery;
            _tweetSearchParameters.SearchType = _searchResultType;
            _tweetSearchParameters.MaximumNumberOfResults = _maximumNumberOfResults;
            _tweetSearchParameters.SinceId = _sinceId;
            _tweetSearchParameters.MaxId = _maxId;
            _tweetSearchParameters.Since = _since;
            _tweetSearchParameters.Until = _until;
            _tweetSearchParameters.Locale = _locale;
            _tweetSearchParameters.Lang = _lang;
            _tweetSearchParameters.GeoCode = _geoCode;
        }
 public bool IsSearchParameterValid(ITweetSearchParameters searchParameters)
 {
     return searchParameters != null && IsAtLeasOneRequiredCriteriaSet(searchParameters);
 }
Ejemplo n.º 43
0
 /// <summary>
 /// Search tweets based on multiple parameters
 /// </summary>
 public static IEnumerable<ITweet> SearchTweets(ITweetSearchParameters tweetSearchParameters)
 {
     return SearchController.SearchTweets(tweetSearchParameters);
 }
Ejemplo n.º 44
0
 public static ISearchResult SearchTweetsWithMetadata(ITweetSearchParameters tweetSearchParameters)
 {
     return SearchController.SearchTweetsWithMetadata(tweetSearchParameters);
 }