예제 #1
0
        public static Tweet TweetMapper(TwitterStatus originalTweet)
        {
            if(originalTweet == null)
                return new Tweet();

            var tweet = new Tweet();
            TwitterStatus twitterStatus;
            if (originalTweet.RetweetedStatus != null)
            {
                tweet.OriginalId = originalTweet.Id;
                tweet.IsRetweeted = true;
                tweet.RetweetedBy = originalTweet.User.Name;
                twitterStatus = originalTweet.RetweetedStatus;
            }
            else
            {
                twitterStatus = originalTweet;
                tweet.OriginalId = twitterStatus.Id;
            }

            tweet.Id = twitterStatus.Id;
            tweet.ImageUrl = twitterStatus.User.ProfileImageUrl;
            tweet.Text = FormatHelper.HtmlToBbCodeText(twitterStatus.TextAsHtml);
            tweet.UserFullName = twitterStatus.User.Name;
            tweet.Created = FormatHelper.UniDate(twitterStatus.CreatedDate);
            tweet.IsNew = true;
            tweet.IsFavorited = twitterStatus.IsFavorited;
            tweet.IsExpanded = true;

            return tweet;
        }
        public void Favorite(Tweet tweet)
        {
            if (tweet.IsFavorited)
                service.UnfavoriteTweet(new UnfavoriteTweetOptions { Id = tweet.OriginalId });
            else
                service.FavoriteTweet(new FavoriteTweetOptions { Id = tweet.OriginalId });

            var twitterResponse = service.Response;
            if (twitterResponse.StatusCode == HttpStatusCode.OK)
                tweet.IsFavorited = !tweet.IsFavorited;
        }
        public void TweetMapper_ReTweet_Valid()
        {
            var date = DateTime.Now;
            var twitterStatus = new TwitterStatus
                {
                    Id = 23,
                    User = new TwitterUser
                        {
                            ProfileImageUrl = "http://mycustom.image.com/myface.jpg",
                            Name = "My Name"
                        },
                    RetweetedStatus = new TwitterStatus
                        {
                            Id = 45,
                            User = new TwitterUser
                            {
                                ProfileImageUrl = "http://mycustom.image.com/myfancyface.jpg",
                                Name = "My Fancy Name"
                            },
                            TextAsHtml = "Awesome! RT <a href=\"https://twitter.com/jhalbrecht\" target=\"_blank\">@jhalbrecht</a> Ah-Ha moments coming Fast and Furious <a href=\"https://twitter.com/ShawnWildermuth\" target=\"_blank\">@ShawnWildermuth</a>'s \"Building a Site with Bootstrap, AngularJS, ASP[.]NET...\"",
                            CreatedDate = date.AddDays(-2),
                            IsFavorited = false
                        },
                    TextAsHtml = "Watching some fish jump @ Issaquah Salmon Days <a href=\"http://instagram.com/p/fJGGVDCndT/\" target=\"_blank\">http://t.co/rPhK2JPvBP</a>",
                    CreatedDate = date,
                    IsFavorited = true
                };

            var expected = new Tweet
                {
                    Id = twitterStatus.RetweetedStatus.Id,
                    Created = FormatHelper.UniDate(twitterStatus.RetweetedStatus.CreatedDate),
                    ImageUrl = twitterStatus.RetweetedStatus.User.ProfileImageUrl,
                    IsExpanded = true,
                    IsFavorited = twitterStatus.RetweetedStatus.IsFavorited,
                    IsNew = true,
                    IsRetweeted = true,
                    OriginalId = twitterStatus.Id,
                    RetweetedBy = twitterStatus.User.Name,
                    Text = FormatHelper.HtmlToBbCodeText(twitterStatus.RetweetedStatus.TextAsHtml),
                    UserFullName = twitterStatus.RetweetedStatus.User.Name
                };

            var tweetMapper = TweetTransformer.TweetMapper(twitterStatus);

            tweetMapper.ShouldBeEquivalentTo(expected);
        }
        public void TweetMapper_Valid()
        {
            var date = DateTime.Now;
            var twitterStatus = new TwitterStatus
                {
                    Id = 23,
                    User = new TwitterUser
                        {
                            ProfileImageUrl = "http://mycustom.image.com/myface.jpg",
                            Name = "My Name"
                        },
                    TextAsHtml = "Watching some fish jump @ Issaquah Salmon Days <a href=\"http://instagram.com/p/fJGGVDCndT/\" target=\"_blank\">http://t.co/rPhK2JPvBP</a>",
                    CreatedDate = date,
                    IsFavorited = true
                };

            var expected = new Tweet
                {
                    Id = twitterStatus.Id,
                    Created = FormatHelper.UniDate(twitterStatus.CreatedDate),
                    ImageUrl = twitterStatus.User.ProfileImageUrl,
                    IsExpanded = true,
                    IsFavorited = twitterStatus.IsFavorited,
                    IsNew = true,
                    IsRetweeted = false,
                    OriginalId = twitterStatus.Id,
                    RetweetedBy = null,
                    Text = FormatHelper.HtmlToBbCodeText(twitterStatus.TextAsHtml),
                    UserFullName = twitterStatus.User.Name
                };

            var tweetMapper = TweetTransformer.TweetMapper(twitterStatus);

            tweetMapper.ShouldBeEquivalentTo(expected);
        }
예제 #5
0
 public void ReTweet(Tweet tweet)
 {
     service.Retweet(new RetweetOptions
     {
         Id = tweet.Id
     });
 }
예제 #6
0
 public void ReadTweet(Tweet tweet)
 {
     tweet.IsNew = false;
 }