Exemple #1
0
        internal TwitterStatus(JsonValue json)
        {
            // read numeric id and timestamp
            Id = json["id_str"].AsString().ParseLong();
            CreatedAt = json["created_at"].AsString().ParseDateTime(ParsingExtension.TwitterDateTimeFormat);

            // check extended_tweet is existed
            var exjson = json.ContainsKey("extended_tweet") ? json["extended_tweet"] : json;

            // read full_text ?? text
            var text = exjson.ContainsKey("full_text") ? exjson["full_text"] : exjson["text"];
            Text = ParsingExtension.ResolveEntity(text.AsString());

            var array = exjson["display_text_range"].AsArrayOrNull()?.AsLongArray();
            if (array != null && array.Length >= 2)
            {
                DisplayTextRange = new Tuple<int, int>((int)array[0], (int)array[1]);
            }

            if (exjson.ContainsKey("extended_entities"))
            {
                // get correctly typed entities array
                var orgEntities = TwitterEntity.ParseEntities(json["entities"]).ToArray();
                var extEntities = TwitterEntity.ParseEntities(json["extended_entities"]).ToArray();

                // merge entities
                Entities = orgEntities.Where(e => !(e is MediaEntity))
                                      .Concat(extEntities) // extended entities contains media entities only.
                                      .ToArray();
            }
            else if (exjson.ContainsKey("entities"))
            {
                Entities = TwitterEntity.ParseEntities(exjson["entities"]).ToArray();
            }
            else
            {
                Entities = new TwitterEntity[0];
            }
            if (json.ContainsKey("recipient"))
            {
                // THIS IS DIRECT MESSAGE!
                StatusType = StatusType.DirectMessage;
                User = new TwitterUser(json["sender"]);
                Recipient = new TwitterUser(json["recipient"]);
            }
            else
            {
                StatusType = StatusType.Tweet;
                User = new TwitterUser(json["user"]);
                Source = json["source"].AsString();
                InReplyToStatusId = json["in_reply_to_status_id_str"].AsString().ParseNullableId();
                InReplyToUserId = json["in_reply_to_user_id_str"].AsString().ParseNullableId();
                InReplyToScreenName = json["in_reply_to_screen_name"].AsString();

                if (json.ContainsKey("retweeted_status"))
                {
                    var retweeted = new TwitterStatus(json["retweeted_status"]);
                    RetweetedStatus = retweeted;
                    RetweetedStatusId = retweeted.Id;
                    // merge text and entities
                    Text = retweeted.Text;
                    Entities = retweeted.Entities;
                }
                if (json.ContainsKey("quoted_status"))
                {
                    var quoted = new TwitterStatus(json["quoted_status"]);
                    QuotedStatus = quoted;
                    QuotedStatusId = quoted.Id;
                }
                var coordinates = json["coordinates"].AsArrayOrNull()?.AsDoubleArray();
                if (coordinates != null)
                {
                    Longitude = coordinates[0];
                    Latitude = coordinates[1];
                }
            }
        }
Exemple #2
0
 public TextEntityDescription(string text, TwitterEntity entity = null)
 {
     Text = text;
     Entity = entity;
 }