Exemplo n.º 1
0
        public Status ParseStatus(JObject obj, long issuer, User creater)
        {
            var status = new Status
            {
                Issuer = new List <long> {
                    issuer
                },
                CreatedAt         = ParseTwitterDateTime(obj["created_at"].ToString()),
                ID                = obj["id"].ToObject <long>(),
                Text              = SafeGetString(obj, "full_text"),
                Source            = obj["source"].ToString(),
                Truncated         = obj["truncated"].ToObject <bool>(),
                ReplyToStatusId   = SafeGetLong(obj, "in_reply_to_status_id"),
                ReplyToUserId     = SafeGetLong(obj, "in_reply_to_user_id"),
                ReplyToScreenName = SafeGetString(obj, "in_reply_to_screen_name"),
                Creater           = creater,
                //TODO: coordinates
                //TODO: place
                QuotedStatusId  = SafeGetLong(obj, "quoted_status_id"),
                IsQuote         = obj["is_quote_status"].ToObject <bool>(),
                QuotedStatus    = SafeGetStatus(obj, "quoted_status", issuer),
                RetweetedStatus = SafeGetStatus(obj, "retweeted_status", issuer),
                RetweetCount    = obj["retweet_count"].ToObject <int>(),
                FavoriteCount   = obj["favorite_count"].ToObject <int>()
            };
            var entities = obj["entities"].ToObject <JObject>();

            if (status.Text == null)
            {
                status.Text = obj["text"].ToString();
            }


            ParseBasicEntitesGroup(status, entities);
            if (entities.ContainsKey("polls"))
            {
                status.Polls = ParseArray(entities["polls"].ToObject <JArray>(), ParsePolls);
            }
            else if (obj.ContainsKey("card"))
            {
                var card     = obj["card"];
                var cardName = card["name"].ToString();
                if (cardName.EndsWith("choice_text_only"))
                {
                    var polls = new Polls();

                    var values = card["binding_values"];

                    polls.DurationMinutes = values["duration_minutes"]["string_value"].ToObject <int>();
                    polls.EndDateTime     = ParsePollsCardDateTime(values["end_datetime_utc"]["string_value"].ToString());
                    polls.URL             = values["api"]["string_value"].ToString();

                    var count = 2;
                    if (cardName == "poll3choice_text_only")
                    {
                        count = 3;
                    }
                    else if (cardName == "poll4choice_text_only")
                    {
                        count = 4;
                    }
                    polls.Options = new Polls.Option[count];
                    for (int i = 0; i < count; i++)
                    {
                        polls.Options[i]  = ParseCardPollsOption(values.ToObject <JObject>(), i + 1);
                        polls.TotalCount += polls.Options[i].Count;
                    }

                    status.Polls = new Polls[] { polls };
                }
            }
            if (obj.ContainsKey("extended_entities"))
            {
                status.ExtendMedias = ParseArray(obj["extended_entities"]["media"].ToObject <JArray>(), ParseExtendMedia);
            }
            status.IsFavortedByUser  = SafeGetBool(obj, "favorited");
            status.IsRetweetedByUser = SafeGetBool(obj, "retweeted");
            status.PossiblySensitive = SafeGetBool(obj, "possibly_sensitive");

            return(StatusFilter.ApplyFilter(status));
        }
Exemplo n.º 2
0
        public User ParseUser(JObject obj, long issuer, bool useFilter)
        {
            var user = new User
            {
                Issuer = new List <long> {
                    issuer
                },

                ID          = obj["id"].ToObject <long>(),
                NickName    = obj["name"].ToString(),
                ScreenName  = obj["screen_name"].ToString(),
                Location    = SafeGetString(obj, "location"),
                URL         = SafeGetString(obj, "url"),
                Description = SafeGetString(obj, "description"),

                //TOOD: derived
                IsProtected     = obj["protected"].ToObject <bool>(),
                IsVerified      = obj["verified"].ToObject <bool>(),
                FollowerCount   = obj["followers_count"].ToObject <long>(),
                FollowingCount  = obj["friends_count"].ToObject <long>(),
                ListedCount     = obj["listed_count"].ToObject <long>(),
                FavouritesCount = obj["favourites_count"].ToObject <long>(),
                StatusesCount   = obj["statuses_count"].ToObject <long>(),
                CreatedAt       = ParseTwitterDateTime(obj["created_at"].ToString()),
                GeoEnabled      = obj["geo_enabled"].ToObject <bool>(),
                Language        = SafeGetString(obj, "lang"),
                //TODO: contributors_enabled
                ProfileBackgroundColor         = obj["profile_background_color"].ToString(),
                ProfileBackgroundImageURL      = obj["profile_background_image_url"].ToString(),
                ProfileHttpsBackgroundImageURL = obj["profile_background_image_url_https"].ToString(),
                ProfileBackgroundTile          = obj["profile_background_tile"].ToObject <bool>(),
                ProfileBannerURL     = SafeGetString(obj, "profile_banner_url"),
                ProfileImageURL      = obj["profile_image_url"].ToString(),
                ProfileHttpsImageURL = obj["profile_image_url_https"].ToString()
            };

            //TODO: profile_link_color
            //TODO: profile_sidebar_border_color
            //TODO: profile_sidebar_fill_color
            //TODO: profile_text_color
            //TODO: profile_use_background_image
            //TODO: default_profile
            //TODO: default_profile_image
            //TODO: withheld_in_countries
            //TODO: withheld_scope

            try
            {
                user.descriptionEntities = new BasicEntitiesGroup();

                var entities = obj["entities"].ToObject <JObject>();

                ParseBasicEntitesGroup(user.descriptionEntities, entities["description"].ToObject <JObject>());

                var urls = entities["url"]?["urls"];
                if (urls != null)
                {
                    user.URLEntities = ParseArray(urls.ToObject <JArray>(), ParseURL);
                }
            }
            catch
            {
            }

            if (!useFilter)
            {
                return(user);
            }

            return(UserFilter.ApplyFilter(user));
        }