public TrendsList GetTrends() { TrendsList trendsList = new TrendsList(); TrendsList currentTrendsList = new TrendsList(); try { TwitterCredentials accessToken = new TwitterAuthService().Authenticate(); string headerName = "Authorization"; string headerValue = accessToken.User + " " + accessToken.Token; JSONConnector JSONConnector = new JSONConnector(); JArray currentTrendsArray = JSONConnector.GetJSONArrayWithHeader(CURRENT_TRENDS_URL, headerName, headerValue); new TwitterTrendsParser().Parse(currentTrendsArray, currentTrendsList); } catch (Exception exception) { ErrorService.Log("TwitterTrendsService", "GetTrends", null, exception); } if (twitterTrendsQueue.Count >= QUEUE_SIZE) { twitterTrendsQueue.Dequeue(); } twitterTrendsQueue.Enqueue(currentTrendsList); foreach (TrendsList twitterTrendsList in twitterTrendsQueue) { trendsList.AddTrends(twitterTrendsList); } return trendsList; }
public SearchResultList Search(SearchContext searchContext) { SearchResultList resultList = new SearchResultList(); try { string urlTemplate; switch (searchContext.SearchType) { case SearchTypeEnum.Tweet: urlTemplate = "https://api.twitter.com/1.1/search/tweets.json?q={0}&count={1}&result_type=mixed&include_entities=false"; break; default: return resultList; } TwitterCredentials accessToken = new TwitterAuthService().Authenticate(); string headerName = "Authorization"; string headerValue = accessToken.User + " " + accessToken.Token; string query = searchContext.Query; int countPerPage = ConfigService.GetConfig(ConfigKeys.THEINTERNETBUZZ_SEARCH_COUNT_PER_PAGE_PER_PROVIDER, 8); int page = searchContext.Page; string url = string.Format(urlTemplate, HttpUtility.UrlEncode(query), countPerPage); JSONConnector JSONConnector = new JSONConnector(); JObject searchResultsJSONObject = JSONConnector.GetJSONObjectWithHeader(url, headerName, headerValue); new TwitterSearchParser().Parse(searchResultsJSONObject, resultList); } catch (Exception exception) { ErrorService.Log("TwitterSearchService", "Search", searchContext.ToString(), exception); } return resultList; }