protected void CallHandler(TwitterStatus status) { if (status.Id > LastSinceId.GetValueOrDefault()) { LastSinceId = status.Id; } _handler(status); }
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]; } } }
public TwitterStatus(JsonValue json) { GenerateFromJson = true; // 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(exjson["entities"]).ToArray(); var extEntities = TwitterEntity.ParseEntities(exjson["extended_entities"]).ToArray(); // merge entities Entities = orgEntities.Where(e => !(e is TwitterMediaEntity)) .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(); FavoriteCount = json["favorite_count"].AsLongOrNull(); RetweetCount = json["retweet_count"].AsLongOrNull(); InReplyToScreenName = json["in_reply_to_screen_name"].AsString(); if (json.ContainsKey("retweeted_status")) { var retweeted = new TwitterStatus(json["retweeted_status"]); RetweetedStatus = retweeted; // merge text and entities Text = retweeted.Text; Entities = retweeted.Entities; } if (json.ContainsKey("quoted_status")) { var quoted = new TwitterStatus(json["quoted_status"]); QuotedStatus = quoted; } var coordinates = json["coordinates"]["coordinates"].AsArrayOrNull()?.AsDoubleArray(); if (coordinates != null && coordinates.Length >= 2) { Coordinates = Tuple.Create(coordinates[0], coordinates[1]); } } }
public void OnStatus(TwitterStatus status) { _receivedStatuses++; }
/// <summary> /// Get sample status and JSON representation. /// </summary> /// <returns></returns> public static IEnumerable<Tuple<TwitterStatus, string>> GetTweetSamples() { var statuses = new[] { _statusJson0, _statusJson1, _statusJson2, _statusJson3, _statusJson4, _statusJson5 }; while (true) { foreach (var status in statuses) { var stobj = new TwitterStatus(MeteorJson.Parse(status)); yield return Tuple.Create(stobj, status); } } }