public Status(JsonData status) { if (status == null) return; Retweeted = status.GetValue<bool>("retweeted"); Source = status.GetValue<string>("source"); InReplyToScreenName = status.GetValue<string>("in_reply_to_screen_name"); PossiblySensitive = status.GetValue<bool>("possibly_sensitive"); RetweetedStatus = new Status(status.GetValue<JsonData>("retweeted_status")); var contributors = status.GetValue<JsonData>("contributors"); Contributors = contributors == null ? new List<Contributor>() : (from JsonData contributor in contributors select new Contributor(contributor)) .ToList(); var coords = status.GetValue<JsonData>("coordinates"); if (coords != null) { Coordinates = new Coordinate(coords.GetValue<JsonData>("coordinates")); } else { Coordinates = new Coordinate(); } Place = new Place(status.GetValue<JsonData>("place")); User = new User(status.GetValue<JsonData>("user")); RetweetCount = status.GetValue<int>("retweet_count"); StatusID = status.GetValue<string>("id_str"); FavoriteCount = status.GetValue<int?>("favorite_count"); Favorited = status.GetValue<bool>("favorited"); InReplyToStatusID = status.GetValue<string>("in_reply_to_status_id_str"); Source = status.GetValue<string>("source"); CreatedAt = status.GetValue<string>("created_at").GetDate(DateTime.MaxValue); InReplyToUserID = status.GetValue<string>("in_reply_to_user_id_str"); Truncated = status.GetValue<bool>("truncated"); Text = status.GetValue<string>("text"); Annotation = new Annotation(status.GetValue<JsonData>("annotation")); Entities = new Entities(status.GetValue<JsonData>("entities")); var currentUserRetweet = status.GetValue<JsonData>("current_user_retweet"); if (currentUserRetweet != null) { CurrentUserRetweet = currentUserRetweet.GetValue<ulong>("id"); } var scopes = status.GetValue<JsonData>("scopes"); Scopes = scopes == null ? new Dictionary<string, string>() : (from key in (scopes as IDictionary<string, JsonData>).Keys as List<string> select new { Key = key, Value = scopes[key].ToString() }) .ToDictionary( key => key.Key, val => val.Value); WithheldCopyright = status.GetValue<bool>("withheld_copyright"); var withheldCountries = status.GetValue<JsonData>("withheld_in_countries"); WithheldInCountries = withheldCountries == null ? new List<string>() : (from JsonData country in status.GetValue<JsonData>("withheld_in_countries") select country.ToString()) .ToList(); WithheldScope = status.GetValue<string>("withheld_scope"); MetaData = new StatusMetaData(status.GetValue<JsonData>("metadata")); Lang = status.GetValue<string>("lang"); string filterLvl = status.GetValue<string>("filter_level"); try { FilterLevel = filterLvl == null ? FilterLevel.None : (FilterLevel)Enum.Parse(typeof(FilterLevel), filterLvl, ignoreCase: true); } catch (ArgumentException) { FilterLevel = FilterLevel.None; } }
public Status(JsonData status) { if (status == null) { return; } JsonData retweetedStatus = status.GetValue <JsonData>("retweeted_status"); RetweetedStatus = new Status(retweetedStatus); Retweeted = retweetedStatus != null; Source = status.GetValue <string>("source"); InReplyToScreenName = status.GetValue <string>("in_reply_to_screen_name"); PossiblySensitive = status.GetValue <bool>("possibly_sensitive"); IsQuotedStatus = status.GetValue <bool>("is_quote_status"); QuotedStatusID = status.GetValue <ulong>("quoted_status_id"); QuotedStatus = new Status(status.GetValue <JsonData>("quoted_status")); JsonData contributors = status.GetValue <JsonData>("contributors"); Contributors = contributors == null ? new List <Contributor>() : (from JsonData contributor in contributors select new Contributor(contributor)) .ToList(); JsonData coords = status.GetValue <JsonData>("coordinates"); Coordinates = coords != null ? new Coordinate(coords.GetValue <JsonData>("coordinates")) : new Coordinate(); Place = new Place(status.GetValue <JsonData>("place")); RetweetCount = status.GetValue <int>("retweet_count"); StatusID = status.GetValue <ulong>("id"); FavoriteCount = status.GetValue <int?>("favorite_count"); Favorited = status.GetValue <bool>("favorited"); InReplyToStatusID = status.GetValue <ulong>("in_reply_to_status_id"); CreatedAt = status.GetValue <string>("created_at").GetDate(DateTime.MaxValue); InReplyToUserID = status.GetValue <ulong>("in_reply_to_user_id"); Truncated = status.GetValue <bool>("truncated"); JsonData displayTextIndices = status.GetValue <JsonData>("display_text_range"); if (displayTextIndices != null) { DisplayTextRange = new List <int> { (int)displayTextIndices[0], (int)displayTextIndices[1] } } ; TweetMode tweetMode; Enum.TryParse(value: status.GetValue <string>("tweet_mode"), ignoreCase: true, result: out tweetMode); TweetMode = tweetMode; Text = status.GetValue <string>("text"); FullText = status.GetValue <string>("full_text"); ExtendedTweet = new Status(status.GetValue <JsonData>("extended_tweet")); Annotation = new Annotation(status.GetValue <JsonData>("annotation")); Entities = new Entities(status.GetValue <JsonData>("entities")); ExtendedEntities = new Entities(status.GetValue <JsonData>("extended_entities")); JsonData currentUserRetweet = status.GetValue <JsonData>("current_user_retweet"); if (currentUserRetweet != null) { CurrentUserRetweet = currentUserRetweet.GetValue <ulong>("id"); } JsonData scopes = status.GetValue <JsonData>("scopes"); Scopes = scopes == null ? new Dictionary <string, string>() : (from key in (scopes as IDictionary <string, JsonData>).Keys as List <string> select new { Key = key, Value = scopes[key].ToString() }) .ToDictionary( key => key.Key, val => val.Value); WithheldCopyright = status.GetValue <bool>("withheld_copyright"); JsonData withheldCountries = status.GetValue <JsonData>("withheld_in_countries"); WithheldInCountries = withheldCountries == null ? new List <string>() : (from JsonData country in status.GetValue <JsonData>("withheld_in_countries") select country.ToString()) .ToList(); WithheldScope = status.GetValue <string>("withheld_scope"); MetaData = new StatusMetaData(status.GetValue <JsonData>("metadata")); Lang = status.GetValue <string>("lang"); FilterLevel filterLevel; Enum.TryParse(value: status.GetValue <string>("filter_level"), ignoreCase: true, result: out filterLevel); FilterLevel = filterLevel; User = new User(status.GetValue <JsonData>("user")); Users = new List <ulong>(); }
public Status(JsonData status) { if (status == null) { return; } Retweeted = status.GetValue <bool>("retweeted"); Source = status.GetValue <string>("source"); InReplyToScreenName = status.GetValue <string>("in_reply_to_screen_name"); PossiblySensitive = status.GetValue <bool>("possibly_sensitive"); RetweetedStatus = new Status(status.GetValue <JsonData>("retweeted_status")); var contributors = status.GetValue <JsonData>("contributors"); Contributors = contributors == null ? new List <Contributor>() : (from JsonData contributor in contributors select new Contributor(contributor)) .ToList(); var coords = status.GetValue <JsonData>("coordinates"); if (coords != null) { Coordinates = new Coordinate(coords.GetValue <JsonData>("coordinates")); } else { Coordinates = new Coordinate(); } Place = new Place(status.GetValue <JsonData>("place")); User = new User(status.GetValue <JsonData>("user")); RetweetCount = status.GetValue <int>("retweet_count"); StatusID = status.GetValue <string>("id_str"); FavoriteCount = status.GetValue <int?>("favorite_count"); Favorited = status.GetValue <bool>("favorited"); InReplyToStatusID = status.GetValue <string>("in_reply_to_status_id_str"); Source = status.GetValue <string>("source"); CreatedAt = status.GetValue <string>("created_at").GetDate(DateTime.MaxValue); InReplyToUserID = status.GetValue <string>("in_reply_to_user_id_str"); Truncated = status.GetValue <bool>("truncated"); Text = status.GetValue <string>("text"); Annotation = new Annotation(status.GetValue <JsonData>("annotation")); Entities = new Entities(status.GetValue <JsonData>("entities")); var currentUserRetweet = status.GetValue <JsonData>("current_user_retweet"); if (currentUserRetweet != null) { CurrentUserRetweet = currentUserRetweet.GetValue <ulong>("id"); } var scopes = status.GetValue <JsonData>("scopes"); Scopes = scopes == null ? new Dictionary <string, string>() : (from key in (scopes as IDictionary <string, JsonData>).Keys as List <string> select new { Key = key, Value = scopes[key].ToString() }) .ToDictionary( key => key.Key, val => val.Value); WithheldCopyright = status.GetValue <bool>("withheld_copyright"); var withheldCountries = status.GetValue <JsonData>("withheld_in_countries"); WithheldInCountries = withheldCountries == null ? new List <string>() : (from JsonData country in status.GetValue <JsonData>("withheld_in_countries") select country.ToString()) .ToList(); WithheldScope = status.GetValue <string>("withheld_scope"); MetaData = new StatusMetaData(status.GetValue <JsonData>("metadata")); Lang = status.GetValue <string>("lang"); string filterLvl = status.GetValue <string>("filter_level"); try { FilterLevel = filterLvl == null ? FilterLevel.None : (FilterLevel)Enum.Parse(typeof(FilterLevel), filterLvl, ignoreCase: true); } catch (ArgumentException) { FilterLevel = FilterLevel.None; } }
public Status(JsonElement status) { if (status.IsNull()) { return; } status.TryGetProperty("retweeted_status", out JsonElement retweetedStatus); RetweetedStatus = new Status(retweetedStatus); Retweeted = !retweetedStatus.IsNull(); Source = status.GetString("source"); InReplyToScreenName = status.GetString("in_reply_to_screen_name"); PossiblySensitive = status.GetBool("possibly_sensitive"); IsQuotedStatus = status.GetBool("is_quote_status"); QuotedStatusID = status.GetUlong("quoted_status_id"); status.TryGetProperty("quoted_status", out JsonElement quotedStatusValue); QuotedStatus = new Status(quotedStatusValue); status.TryGetProperty("contributors", out JsonElement contributors); Contributors = contributors.IsNull() ? new List <Contributor>() : (from contributor in contributors.EnumerateArray() select new Contributor(contributor)) .ToList(); status.TryGetProperty("coordinates", out JsonElement coords); if (!coords.IsNull()) { coords.TryGetProperty("coordinates", out JsonElement coordsValue); Coordinates = new Coordinate(coordsValue); } else { Coordinates = new Coordinate(); } status.TryGetProperty("place", out JsonElement placeValue); Place = new Place(placeValue); RetweetCount = status.GetInt("retweet_count"); StatusID = status.GetUlong("id"); FavoriteCount = status.GetInt("favorite_count"); Favorited = status.GetBool("favorited"); InReplyToStatusID = status.GetUlong("in_reply_to_status_id"); CreatedAt = status.GetDate("created_at", DateTime.MaxValue); InReplyToUserID = status.GetUlong("in_reply_to_user_id"); Truncated = status.GetBool("truncated"); status.TryGetProperty("display_text_range", out JsonElement displayTextRange); if (!displayTextRange.IsNull()) { JsonElement[] displayTextIndices = displayTextRange.EnumerateArray().ToArray(); DisplayTextRange = new List <int> { displayTextIndices[0].GetInt32(), displayTextIndices[1].GetInt32() }; } TweetMode tweetMode; Enum.TryParse(value: status.GetString("tweet_mode"), ignoreCase: true, result: out tweetMode); TweetMode = tweetMode; Text = status.GetString("text"); FullText = status.GetString("full_text"); status.TryGetProperty("extended_tweet", out JsonElement extendedTweetValue); ExtendedTweet = new Status(extendedTweetValue); status.TryGetProperty("annotation", out JsonElement annotationValue); Annotation = new Annotation(annotationValue); status.TryGetProperty("entities", out JsonElement entitiesValue); Entities = new Entities(entitiesValue); status.TryGetProperty("extended_entities", out JsonElement extendedEntitiesValue); ExtendedEntities = new Entities(extendedEntitiesValue); status.TryGetProperty("current_user_retweet", out JsonElement currentUserRetweet); if (!currentUserRetweet.IsNull()) { CurrentUserRetweet = currentUserRetweet.GetProperty("id").GetUInt64(); } // TODO: We need a good example of a scope so we can write a test. //JsonElement scopes = status.GetProperty("scopes"); //Scopes = // scopes.IsNull() ? new Dictionary<string, string>() : // (from key in (scopes as IDictionary<string, JsonData>).Keys as List<string> // select new // { // Key = key, // Value = scopes[key].ToString() // }) // .ToDictionary( // key => key.Key, // val => val.Value); WithheldCopyright = status.GetBool("withheld_copyright"); status.TryGetProperty("withheld_in_countries", out JsonElement withheldCountries); if (withheldCountries.IsNull()) { WithheldInCountries = new List <string>(); } else { WithheldInCountries = (from country in withheldCountries.EnumerateArray() select country.GetString()) .ToList(); } WithheldScope = status.GetString("withheld_scope"); status.TryGetProperty("metadata", out JsonElement metadataValue); MetaData = new StatusMetaData(metadataValue); Lang = status.GetString("lang"); FilterLevel filterLevel; Enum.TryParse(value: status.GetString("filter_level"), ignoreCase: true, result: out filterLevel); FilterLevel = filterLevel; status.TryGetProperty("user", out JsonElement userValue); User = new User(userValue); Users = new List <ulong>(); }