예제 #1
0
        private void SetTextAndEntities(dynamic root)
        {
            if (root.full_text())
            {
                this.Text = ParsingExtension.ResolveEntity(root.full_text);
            }
            else if (root.text())
            {
                this.Text = ParsingExtension.ResolveEntity(root.text);
            }
            if (root.extended_entities())
            {
                // get correctly typed entities array
                var orgEntities = (TwitterEntity[])Enumerable.ToArray(TwitterEntity.GetEntities(root.entities));
                var extEntities = (TwitterEntity[])Enumerable.ToArray(TwitterEntity.GetEntities(root.extended_entities));

                // merge entities
                this.Entities = orgEntities
                                .Where(e => e.EntityType != EntityType.Media)
                                .Concat(extEntities) // extended entities contains media entities only.
                                .ToArray();
            }
            else if (root.entities())
            {
                this.Entities = Enumerable.ToArray(TwitterEntity.GetEntities(root.entities));
            }
            else
            {
                this.Entities = new TwitterEntity[0];
            }
        }
예제 #2
0
        public string GetEntityAidedDescription(bool showFullUrl = false)
        {
            var           builder    = new StringBuilder();
            var           escaped    = this.Description ?? String.Empty;
            TwitterEntity prevEntity = null;

            foreach (var entity in this.DescriptionEntities.Guard().OrderBy(e => e.StartIndex))
            {
                var pidx = 0;
                if (prevEntity != null)
                {
                    pidx = prevEntity.EndIndex;
                }
                if (pidx < entity.StartIndex)
                {
                    // output raw
                    builder.Append(ParsingExtension.ResolveEntity(escaped.Substring(pidx, entity.StartIndex - pidx)));
                }
                switch (entity.EntityType)
                {
                case EntityType.Hashtags:
                    builder.Append("#" + entity.DisplayText);
                    break;

                case EntityType.Urls:
                    builder.Append(showFullUrl
                                           ? ParsingExtension.ResolveEntity(entity.OriginalUrl)
                                           : ParsingExtension.ResolveEntity(entity.DisplayText));
                    break;

                case EntityType.Media:
                    builder.Append(showFullUrl
                                           ? ParsingExtension.ResolveEntity(entity.MediaUrl)
                                           : ParsingExtension.ResolveEntity(entity.DisplayText));
                    break;

                case EntityType.UserMentions:
                    builder.Append("@" + entity.DisplayText);
                    break;
                }
                prevEntity = entity;
            }
            if (prevEntity == null)
            {
                builder.Append(ParsingExtension.ResolveEntity(escaped));
            }
            else if (prevEntity.EndIndex < escaped.Length)
            {
                builder.Append(ParsingExtension.ResolveEntity(
                                   escaped.Substring(prevEntity.EndIndex, escaped.Length - prevEntity.EndIndex)));
            }
            return(builder.ToString());
        }
예제 #3
0
 public TwitterStatus(dynamic json)
 {
     this.GenerateFromJson = true;
     this.Id        = ((string)json.id_str).ParseLong();
     this.CreatedAt = ((string)json.created_at).ParseDateTime(ParsingExtension.TwitterDateTimeFormat);
     this.Text      = ParsingExtension.ResolveEntity(json.text);
     this.Entities  = Enumerable.ToArray(TwitterEntity.GetEntities(json.entities));
     if (json.recipient())
     {
         // THIS IS DIRECT MESSAGE!
         this.StatusType = StatusType.DirectMessage;
         this.User       = new TwitterUser(json.sender);
         this.Recipient  = new TwitterUser(json.recipient);
     }
     else
     {
         this.StatusType = StatusType.Tweet;
         this.User       = new TwitterUser(json.user);
         this.Source     = json.source;
         if (json.in_reply_to_status_id_str())
         {
             this.InReplyToStatusId = ((string)json.in_reply_to_status_id_str).ParseNullableId();
         }
         if (json.in_reply_to_user_id_str())
         {
             this.InReplyToUserId = ((string)json.in_reply_to_user_id_str).ParseNullableId();
         }
         if (json.in_reply_to_screen_name())
         {
             this.InReplyToScreenName = json.in_reply_to_screen_name;
         }
         if (json.retweeted_status())
         {
             var original = new TwitterStatus(json.retweeted_status);
             this.RetweetedOriginal   = original;
             this.RetweetedOriginalId = original.Id;
             // merge text and entities
             this.Text     = original.Text;
             this.Entities = original.Entities.Guard().ToArray();
         }
         if (json.coordinates() && json.coordinates != null)
         {
             this.Longitude = (double)json.coordinates.coordinates[0];
             this.Latitude  = (double)json.coordinates.coordinates[1];
         }
     }
 }
예제 #4
0
 public TwitterUser(dynamic json)
 {
     this.Id                        = ((string)json.id_str).ParseLong();
     this.ScreenName                = ParsingExtension.ResolveEntity(json.screen_name);
     this.Name                      = ParsingExtension.ResolveEntity(json.name ?? String.Empty);
     this.Description               = ParsingExtension.ResolveEntity(json.description ?? String.Empty);
     this.Location                  = ParsingExtension.ResolveEntity(json.location ?? String.Empty);
     this.Url                       = json.url;
     this.IsDefaultProfileImage     = json.default_profile_image;
     this.ProfileImageUri           = ((string)json.profile_image_url).ParseUri();
     this.ProfileBackgroundImageUri = ((string)json.profile_background_image_url).ParseUri();
     if (json.profile_banner_url())
     {
         this.ProfileBannerUri = ((string)json.profile_banner_url).ParseUri();
     }
     this.IsProtected           = json["protected"];
     this.IsVerified            = json.verified;
     this.IsTranslator          = json.is_translator;
     this.IsContributorsEnabled = json.contributors_enabled;
     this.IsGeoEnabled          = json.geo_enabled;
     this.StatusesCount         = (long)((double?)json.statuses_count ?? default(double));
     this.FollowingsCount       = (long)((double?)json.friends_count ?? default(double));
     this.FollowersCount        = (long)((double?)json.followers_count ?? default(double));
     this.FavoritesCount        = (long)((double?)json.favourites_count ?? default(double));
     this.ListedCount           = (long)((double?)json.listed_count ?? default(double));
     this.Language  = json.lang;
     this.CreatedAt = ((string)json.created_at).ParseDateTime(ParsingExtension.TwitterDateTimeFormat);
     if (json.entities())
     {
         if (json.entities.url())
         {
             UrlEntities = Enumerable.ToArray(TwitterEntity.GetEntities(json.entities.url));
         }
         if (json.entities.description())
         {
             DescriptionEntities = Enumerable.ToArray(TwitterEntity.GetEntities(json.entities.description));
         }
     }
 }
예제 #5
0
 public TwitterStatus()
 {
     this.GenerateFromJson = false;
     Entities = new TwitterEntity[0];
 }
예제 #6
0
 public TextEntityDescription(string text, TwitterEntity entity = null)
 {
     _text = text;
     _entity = entity;
 }
예제 #7
0
 public TwitterStatus()
 {
     this.GenerateFromJson = false;
     Entities = new TwitterEntity[0];
 }