Ejemplo n.º 1
0
        public RootObject getTweet(TweetRequest tweetRequest)
        {
            string baseURL  = ConfigurationManager.AppSettings["baseURL"].ToString();
            string endPoint = ConfigurationManager.AppSettings["entryPoint"].ToString();
            string URI      = baseURL + endPoint + "?startDate=" + tweetRequest.startDate + "&endDate=" + tweetRequest.endDate;

            List <RootObject> tweetResponselist = new List <RootObject>();
            RootObject        tweetResponse     = null;
            HttpWebRequest    httpWebRequest    = null;
            HttpWebResponse   httpWebResponse   = null;

            try
            {
                httpWebRequest             = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URI);
                httpWebRequest.Method      = "GET";
                httpWebRequest.ContentType = "text/plain";

                //Get Response
                httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
                {
                    string result = streamReader.ReadToEnd();
                    tweetResponse = JsonConvert.DeserializeObject <RootObject>(result);
                    tweetResponselist.Add(tweetResponse);
                    checkForData(tweetResponselist.Count(), tweetRequest, tweetResponselist);
                }
            }
            catch (HttpException httpException) { }
            catch (Exception exception) { }
            return(tweetResponse);
        }
 private async void LoadTweets()
 {
     var tweetRequest = new TweetRequest(Palestrante.Twitter);
     var tweets = await tweetRequest.BaseList();
     if (tweets != null)
         foreach (var tweet in tweets)
             UltimosTweets.Add(tweet);
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateTweet(TweetRequest tweetRequest)
        {
            var createdTweet = await _tweetsService
                               .CreateTweet(tweetRequest, User.GetId());

            return(CreatedAtAction(nameof(GetTweet),
                                   new { id = createdTweet.Id },
                                   createdTweet));
        }
Ejemplo n.º 4
0
        public static images RequestToTweet(TweetRequest entity)
        {
            var tweet = new images()
            {
                TweetId   = entity.TweetId,
                text      = entity.Text,
                media_url = entity.MediaUrl
            };

            return(tweet);
        }
Ejemplo n.º 5
0
        // GET: Tweet
        public ActionResult Index()
        {
            TweetRequest tweetRequest = new TweetRequest();

            tweetRequest.startDate = "2016-03-20"; //testing purpose
            tweetRequest.endDate   = "2017-03-20"; //testing purpose
            BusinessLogic businessLogic = new BusinessLogic();
            RootObject    tweetResponse = businessLogic.getTweet(tweetRequest);

            return(View());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> UpdateTweet(int id, TweetRequest updatedTweetRequest)
        {
            var actionResult = await _tweetsService.UpdateTweet(id, updatedTweetRequest, User.GetId());

            return(actionResult switch
            {
                ServiceStatus.Success => NoContent(),
                ServiceStatus.NotFound => BadRequest(),
                ServiceStatus.UnauthorizedAction => Unauthorized(),
                _ => throw new ArgumentOutOfRangeException()
            });
Ejemplo n.º 7
0
        public static images ToDataModel(TweetRequest entity)
        {
            var image = new images
            {
                TweetId   = entity.TweetId,
                text      = entity.Text,
                media_url = entity.MediaUrl
            };

            return(image);
        }
Ejemplo n.º 8
0
        private async void LoadTweets()
        {
            var tweetRequest = new TweetRequest(Palestrante.Twitter);
            var tweets       = await tweetRequest.BaseList();

            if (tweets != null)
            {
                foreach (var tweet in tweets)
                {
                    UltimosTweets.Add(tweet);
                }
            }
        }
Ejemplo n.º 9
0
 public void checkForData(int count, TweetRequest request, List <RootObject> getTweetList)
 {
     if (count.Equals(100))
     {
         TweetRequest tweetRequest = new TweetRequest();
         if (getTweetList.Last().stamp < DateTime.Parse(request.endDate))
         {
             tweetRequest.startDate = getTweetList.Last().stamp.ToString();
             tweetRequest.endDate   = request.endDate;
             getTweet(tweetRequest);
         }
     }
 }
        public async Task <IActionResult> PostTweetAsync([FromBody] TweetRequest tweet)
        {
            var tweetToPost = new Tweet
            {
                Message    = tweet.TweetMessage,
                UserId     = int.Parse(HttpContext.GetUserId()),
                TimePosted = DateTime.Now
            };

            var response = await _tweetService.PostTweetAsync(tweetToPost);

            return(Ok(response));
        }
Ejemplo n.º 11
0
        public async Task <TweetResponse> CreateTweet(
            TweetRequest tweetRequest, string userId)
        {
            var tweet = _mapper.Map <TweetRequest, Tweet>(tweetRequest);

            tweet.UserID         = userId;
            tweet.CreationDate   = DateTime.UtcNow;
            tweet.LastTimeOfEdit = tweet.CreationDate;

            await _tweetsRepository.CreateTweet(tweet);

            var tweetDto = _mapper.Map <Tweet, TweetResponse>(tweet);

            return(tweetDto);
        }
Ejemplo n.º 12
0
        public async Task <List <Business.Contracts.Tweet> > GetTweetInfo(DateTime startDate, DateTime endDate)
        {
            List <Business.Contracts.Tweet> response = new List <Business.Contracts.Tweet>();

            try
            {
                TweetRequest tweetRequest = new TweetRequest();
                tweetRequest.StartDate = startDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
                tweetRequest.EndDate   = endDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");

                using (HttpClientWrapper httpClient = new HttpClientWrapper("https://badapi.iqvia.io/api/v1/Tweets", string.Format("?startDate={0}&endDate={1}", tweetRequest.StartDate, tweetRequest.EndDate), "application/json"))
                {
                    response = await httpClient.GetData <Business.Contracts.Tweet>();
                }
            }
            catch (Exception exception)
            {
            }

            return(response);
        }
Ejemplo n.º 13
0
        public async Task <ServiceStatus> UpdateTweet(int id,
                                                      TweetRequest updatedTweetRequest, string userId)
        {
            var tweet = await _tweetsRepository.GetTweet(id);

            if (tweet == null)
            {
                return(ServiceStatus.NotFound);
            }

            if (!tweet.UserID.Equals(userId))
            {
                return(ServiceStatus.UnauthorizedAction);
            }

            tweet.TweetContent   = updatedTweetRequest.Content;
            tweet.LastTimeOfEdit = DateTime.UtcNow;
            await _tweetsRepository.UpdateTweet(tweet.ID, tweet);

            return(ServiceStatus.Success);
        }
Ejemplo n.º 14
0
        public static void Main(string[] args)
        {
            Uri tokenUri = new Uri("https://api.twitter.com/oauth2/token");
            Uri userTimelineUri = new Uri("https://api.twitter.com/1.1/statuses/user_timeline.json");

            var twitter = new Twitter();

            var credential = new BearerTokenCredential(ConsumerKey, ConsumerSecret);
            var tokenRequest = new BearerTokenRequest(credential, tokenUri);

            IBearerToken token= twitter.RequestBearerToken(tokenRequest);

            Console.WriteLine(token);

            string screenName = "JohnRentoul";
            var tweetsRequest = new TweetRequest(token, userTimelineUri, screenName);

            var tweets = twitter.GetTweets(tweetsRequest);

            Console.WriteLine();
            Console.WriteLine("--------");
            Console.WriteLine();

            List<SyndicationItem> items = new List<SyndicationItem>();
            int counter = 0;
            foreach (var tweet in tweets)
            {
                if (tweet.ContainsLinks)
                {
                    counter++;
                    foreach (var link in tweet.Links)
                    {
                        Console.WriteLine(link.AbsoluteUri);
                    }

                    StringBuilder content = new StringBuilder();
                    content.AppendLine(tweet.text);
                    foreach(var link in tweet.Links)
                    {
                        string linkTag = string.Format(@"<a href='{0}'>{0}</>", link.AbsoluteUri);
                        content.AppendLine(linkTag);
                    }
                    SyndicationItem item = new SyndicationItem(screenName + counter, content.ToString(), new Uri("http://localhost"));
                    items.Add(item);
                }
            }

            var syndicationFeed = new SyndicationFeed("LinkTwrapper", "Tweets containing links", new Uri("http://localhost"))
                { Items = items };
            string timestamp = DateTime.Now.ToString("yyyy-MM-dd_hhmmssfff");
            string filePath = string.Format(@"C:\WS\LinkTwrapper\RSSFiles\Tweets{0}.rss", timestamp);
            using (var fileStream = File.Create(filePath))
            {
                using (var xmlWriter = XmlWriter.Create(fileStream))
                {
                    syndicationFeed.SaveAsRss20(xmlWriter);
                    xmlWriter.Flush();
                }
            }

            Console.ReadLine();
        }
Ejemplo n.º 15
0
 //[Authorize]
 public int Create([FromBody] TweetRequest request)
 {
     return(_service.Create(request));
 }
Ejemplo n.º 16
0
        private static async Task GetTweets(TokenAuth auth, TweetRequest tweetRequest)
        {
            try
            {
                using (var handler = new HttpClientHandler())
                {
                    handler.ServerCertificateCustomValidationCallback =
                        (message, cert, chain, errors) => { return(true); };
                    using (var httpClient = new HttpClient(handler))
                        using (var client = new HttpClient(handler))
                        {
                            string baseAddress = "https://api.twitter.com/1.1/tweets/search/30day/analysis.json";

                            client.DefaultRequestHeaders.Add("Authorization", $"Bearer  {auth.AccessToken}");

                            int index = 1;
                            do
                            {
                                Console.WriteLine($"Page: {index++}");
                                var json          = JsonConvert.SerializeObject(tweetRequest);
                                var stringContent = new StringContent(json);
                                var request       = client.PostAsync(baseAddress, stringContent).Result;
                                var content       = await request.Content.ReadAsStringAsync();

                                await FileHelper.WriteFile($"wcf-{index}.json", content);

                                var result = JsonConvert.DeserializeObject <TweetResult>
                                             (
                                    content,
                                    new IsoDateTimeConverter
                                {
                                    DateTimeFormat = "ddd MMM dd HH:mm:ss K yyyy",
                                    Culture        = new System.Globalization.CultureInfo("en-US")
                                }
                                             );
                                Console.WriteLine($"Found: {result.Results.Count}");
                                tweetRequest.Next = result.Next;
                                result.Results.ForEach(x =>
                                {
                                    // Normalize ID, for store.
                                    if (x.QuotedStatusId == 0)
                                    {
                                        x.QuotedStatusId = null;
                                    }
                                    if (x.RetweetedStatusId == 0)
                                    {
                                        x.RetweetedStatusId = null;
                                    }
                                    if (x.ExtendedTweet != null)
                                    {
                                        x.ExtendedTweet.TweetRawId = x.Id;
                                    }
                                });
                            } while (!string.IsNullOrEmpty(tweetRequest.Next));
                        }
                }
            }
            catch (Exception ex)
            {
                var message = ex.Message;
            }
        }