public async Task <ActionResult> PullTweets([FromBody] PullTweetViewModel model) { if (ModelState.IsValid) { var userId = User.Claims.First(x => x.Type == "UserID").Value; var user = await _userRepo.GetUserById(userId); APIDetails details = _contextRepo.GetAPIDetails(user); var tweet = _helper.GetTweets(model, details); if (tweet.Any()) { string filename = model.Title; bool fileExist = _contextRepo.FileNameExist(model.Title); if (fileExist) { filename = model.Title + "_" + Guid.NewGuid(); } _helper.CreateCsv(tweet, filename); var pullDetails = new PullDetails() { User = user, Title = model.Title, Keyword = model.Keyword, FileName = filename, Quantity = model.Quantity, Date = DateTime.UtcNow }; _contextRepo.Create(pullDetails); return(Ok()); } return(Ok("tweet is null")); } return(BadRequest()); }
public IEnumerable <ITweet> GetTweets(PullTweetViewModel model, APIDetails details) { try { // Get a AuthenticatedUser from a specific set of credentials Auth.SetUserCredentials(details.ApiKey, details.ApiSecretKey, details.AccessToken, details.AccessTokenSecret); //var authenticatedUser = User.GetAuthenticatedUser(userCredentials); var from = Convert.ToDateTime(model.From); var to = Convert.ToDateTime(model.To); var searchParameter = new SearchTweetsParameters(model.Keyword) { //GeoCode = new GeoCode(9.0820, 8.6753, 1, DistanceMeasure.Miles), Lang = LanguageFilter.English, //SearchType = SearchResultType.Popular, MaximumNumberOfResults = model.Quantity, //Until = new DateTime(2019, 08, 02), //Since = from.Date, //Until = to.Date, //SinceId = 399616835892781056, //MaxId = 405001488843284480, //Filters = TweetSearchFilters.Images | TweetSearchFilters.Verified }; IEnumerable <ITweet> tweets = Search.SearchTweets(searchParameter); return(tweets); } catch (Exception) { throw; } }