Example #1
0
 public static List <TweetViewModel> Create(TwitterSearchResponse response)
 {
     return(response.statuses.Select(status => new TweetViewModel
     {
         User = $"@{status.user.screen_name}",
         Text = status.text,
         GpsCoordinates = new GeoPoint
         {
             Latitude = status.coordinates.coordinates.Last(),
             Longitude = status.coordinates.coordinates.First()
         }
     }).ToList());
 }
Example #2
0
        private void HandleUrlInTweetText(TwitterSearchResponse response)
        {
            foreach (var tweet in response.statuses)
            {
                var fullText = tweet.full_text;

                var indexOfTweetUrl = fullText.IndexOf("https://t.co");

                if (indexOfTweetUrl == -1)
                {
                    continue;
                }

                tweet.full_text = fullText.Replace(fullText.Substring(indexOfTweetUrl), string.Empty);
            }
        }
Example #3
0
        public static TweetsViewModel Create(TwitterSearchResponse response)
        {
            var viewModel = new TweetsViewModel();

            foreach (var status in response.statuses)
            {
                var tweet = new TweetViewModel
                {
                    User = $"@{status.user.screen_name}",
                    Text = status.text,
                    //ImageUrl = status.user.entities.url.urls.FirstOrDefault() == null ? string.Empty : status.user.entities.url.urls.FirstOrDefault().expanded_url
                };
                viewModel.Tweets.Add(tweet);
            }

            return(viewModel);
        }
Example #4
0
        private TwitterSearchResponse MakeSearchRequest(string url)
        {
            var searchResponse = new TwitterSearchResponse();

            using (var client = new HttpClient())
            {
                var authorizationHeader = GetAuthorizationHeader();

                if (string.IsNullOrEmpty(authorizationHeader))
                {
                    SetError("Bearer Token Not Available");
                }
                else
                {
                    client.DefaultRequestHeaders.Add("Authorization", authorizationHeader);

                    try
                    {
                        var response = client.GetAsync(url).Result;

                        var content = response.Content.ReadAsStringAsync().Result;

                        if (response.StatusCode == System.Net.HttpStatusCode.OK)
                        {
                            searchResponse = (ParseSearchJson(content));

                            HandleUrlInTweetText(searchResponse);
                        }
                        else
                        {
                            SetError($"{response.StatusCode.ToString()}: {content}");
                        }
                    }
                    catch (Exception e)
                    {
                        SetError($"Unable to perform search: {e}");
                    }
                }
            }

            return(searchResponse);
        }