private TwitterStatus( long id, StatusType statusType, [NotNull] TwitterUser user, [NotNull] string text, [CanBeNull] Tuple <int, int> displayTextRange, DateTime createdAt, [NotNull] TwitterEntity[] entities) { Id = id; StatusType = statusType; User = user ?? throw new ArgumentNullException(nameof(user)); User = user; Text = text ?? throw new ArgumentNullException(nameof(text)); DisplayTextRange = displayTextRange; CreatedAt = createdAt; Entities = entities ?? throw new ArgumentNullException(nameof(entities)); }
internal TwitterList(JsonValue json) { Id = json["id_str"].AsString().ParseLong(); User = new TwitterUser(json["user"]); Name = json["name"].AsString() ?? String.Empty; FullName = json["full_name"].AsString() ?? String.Empty; Uri = new Uri(TwitterListUriPrefix + json["uri"].AsString()); Slug = json["slug"].AsString().AssertNotNull("json.slug could not be null."); ListMode = json["mode"].AsString() == "public" ? ListMode.Public : ListMode.Private; Description = json["description"].AsString() ?? String.Empty; MemberCount = json["member_count"].AsLong(); SubscriberCount = json["subscriber_count"].AsLong(); CreatedAt = json["created_at"].AsString().ParseDateTime(ParsingExtension.TwitterDateTimeFormat); }
public TwitterList(JsonValue json) { Id = json["id_str"].AsString().ParseLong(); User = new TwitterUser(json["user"]); Name = json["name"].AsString(); FullName = json["full_name"].AsString(); Uri = new Uri(TwitterListUriPrefix + json["uri"].AsString()); Slug = json["slug"].AsString(); ListMode = json["mode"].AsString() == "public" ? ListMode.Public : ListMode.Private; Description = json["description"].AsStringOrNull() ?? String.Empty; MemberCount = json["member_count"].AsLong(); SubscriberCount = json["subscriber_count"].AsLong(); CreatedAt = json["created_at"].AsString().ParseDateTime(ParsingExtension.TwitterDateTimeFormat); }
public TwitterList( long id, [NotNull] TwitterUser user, [NotNull] string name, [NotNull] string fullName, [NotNull] Uri uri, [NotNull] string slug, ListMode mode, [CanBeNull] string description, long memberCount, long subscriberCount, DateTime createdAt) { Id = id; User = user ?? throw new ArgumentNullException(nameof(user)); Name = name ?? throw new ArgumentNullException(nameof(name)); FullName = fullName ?? throw new ArgumentNullException(nameof(fullName)); Uri = uri ?? throw new ArgumentNullException(nameof(uri)); Slug = slug ?? throw new ArgumentNullException(nameof(slug)); ListMode = mode; Description = description ?? String.Empty; MemberCount = memberCount; SubscriberCount = subscriberCount; CreatedAt = createdAt; }
public TwitterStatus( long id, [NotNull] TwitterUser user, [NotNull] string text, [CanBeNull] Tuple <int, int> displayTextRange, DateTime createdAt, [NotNull] TwitterEntity[] entities, [CanBeNull] string source, long?inReplyToStatusId, long?inReplyToUserId, long[] favs, long[] rts, [CanBeNull] string inReplyToScreenName, [CanBeNull] Tuple <double, double> coordinates, [CanBeNull] TwitterStatus retweetedStatus, [CanBeNull] TwitterStatus quotedStatus) : this(id, StatusType.Tweet, user, text, displayTextRange, createdAt, entities) { Source = source; InReplyToStatusId = inReplyToStatusId; InReplyToScreenName = inReplyToScreenName; InReplyToUserId = inReplyToUserId; FavoritedUsers = favs; FavoriteCount = favs.Length; RetweetedUsers = rts; RetweetCount = rts.Length; Coordinates = coordinates; RetweetedStatus = retweetedStatus; QuotedStatus = quotedStatus; }
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]; } } }
/// <summary> /// Parse streamed twitter event /// </summary> /// <param name="ev">event name</param> /// <param name="graph">JSON object graph</param> /// <param name="handler">result handler</param> private static void ParseStreamEvent(string ev, JsonValue graph, IStreamHandler handler) { try { var source = new TwitterUser(graph[EventSourceKey]); var target = new TwitterUser(graph[EventTargetKey]); var timestamp = graph[EventCreatedAtKey].AsString().ParseTwitterDateTime(); switch (ev) { case "favorite": case "unfavorite": case "quoted_tweet": case "favorited_retweet": case "retweeted_retweet": handler.OnMessage(new StreamStatusEvent(source, target, new TwitterStatus(graph[EventTargetObjectKey]), ev, timestamp)); break; case "block": case "unblock": case "follow": case "unfollow": case "mute": case "unmute": case "user_update": case "user_delete": case "user_suspend": handler.OnMessage(new StreamUserEvent(source, target, ev, timestamp)); break; case "list_created": case "list_destroyed": case "list_updated": case "list_member_added": case "list_member_removed": case "list_user_subscribed": case "list_user_unsubscribed": handler.OnMessage(new StreamListEvent(source, target, new TwitterList(graph[EventTargetObjectKey]), ev, timestamp)); break; case "access_revoked": case "access_unrevoked": handler.OnMessage(new StreamAccessInformationEvent(source, target, new AccessInformation(graph[EventTargetObjectKey]), ev, timestamp)); break; } } catch (Exception ex) { handler.OnException(new StreamParseException( "Event parse failed:" + ev, graph.ToString(), ex)); } }
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]); } } }