Пример #1
0
 public List(JsonElement element) : this()
 {
     Name        = element.GetString("name");
     FullName    = element.GetString("full_name");
     MemberCount = element.GetInt("member_count");
     Description = element.GetString("description");
     Mode        = element.GetString("mode");
     Uri         = element.GetString("uri");
     Users       = new List <User> {
         new User(element.GetProperty("user"))
     };
     ListIDResponse  = element.GetUlong("id");
     SubscriberCount = element.GetInt("subscriber_count");
     CreatedAt       = element.GetString("created_at")?.GetDate(DateTime.MaxValue);
     Following       = element.GetBool("following");
     SlugResponse    = element.GetString("slug");
 }
Пример #2
0
        public Relationship(JsonElement relJson)
        {
            if (relJson.IsNull())
            {
                return;
            }

            ScreenName           = relJson.GetString("screen_name");
            Name                 = relJson.GetString("name");
            RetweetsWanted       = relJson.GetBool("want_retweets");
            AllReplies           = relJson.GetBool("all_replies");
            MarkedSpam           = relJson.GetBool("marked_spam");
            ID                   = relJson.GetUlong("id");
            Blocking             = relJson.GetBool("blocking");
            NotificationsEnabled = relJson.GetBool("notifications_enabled");
            CanDm                = relJson.GetBool("can_dm");
            Muting               = relJson.GetBool("muting", false);

            if (relJson.TryGetProperty("connections", out JsonElement connections))
            {
                Connections =
                    (from connection in connections.EnumerateArray()
                     select connection.ToString())
                    .ToList();
            }
            else
            {
                Connections = new List <string>();
            }

            FollowedBy =
                relJson.GetBool("followed_by") ||
                Connections.Contains("followed_by");
            Following =
                relJson.GetBool("following") ||
                Connections.Contains("following");
        }
Пример #3
0
 internal SleepTime(JsonElement sleepTime)
 {
     StartHour = sleepTime.GetInt("start_time");
     EndHour   = sleepTime.GetInt("end_time");
     Enabled   = sleepTime.GetBool("enabled");
 }
Пример #4
0
        public User(JsonElement user)
        {
            if (user.IsNull())
            {
                return;
            }

            BannerSizes        = new List <BannerSize>();
            Categories         = new List <Category>();
            UserIDResponse     = user.GetUlong("id").ToString(CultureInfo.InvariantCulture);
            ScreenNameResponse = user.GetString("screen_name");
            Name                 = user.GetString("name");
            Location             = user.GetString("location");
            Description          = user.GetString("description");
            ProfileImageUrl      = user.GetString("profile_image_url");
            ProfileImageUrlHttps = user.GetString("profile_image_url_https");
            Url = user.GetString("url");
            user.TryGetProperty("entities", out JsonElement entitiesValue);
            Entities  = new UserEntities(entitiesValue);
            Protected = user.GetBool("protected");
            ProfileUseBackgroundImage = user.GetBool("profile_use_background_image");
            IsTranslator              = user.GetBool("is_translator");
            FollowersCount            = user.GetInt("followers_count");
            DefaultProfile            = user.GetBool("default_profile");
            ProfileBackgroundColor    = user.GetString("profile_background_color");
            LangResponse              = user.GetString("lang");
            ProfileTextColor          = user.GetString("profile_text_color");
            ProfileLinkColor          = user.GetString("profile_link_color");
            ProfileSidebarFillColor   = user.GetString("profile_sidebar_fill_color");
            ProfileSidebarBorderColor = user.GetString("profile_sidebar_border_color");
            FriendsCount              = user.GetInt("friends_count");
            DefaultProfileImage       = user.GetBool("default_profile_image");
            CreatedAt                      = (user.GetString("created_at") ?? string.Empty).GetDate(DateTime.MinValue);
            FavoritesCount                 = user.GetInt("favourites_count");
            UtcOffset                      = user.GetInt("utc_offset");
            TimeZone                       = user.GetString("time_zone");
            ProfileBackgroundImageUrl      = user.GetString("profile_background_image_url");
            ProfileBackgroundImageUrlHttps = user.GetString("profile_background_image_url_https");
            ProfileBackgroundTile          = user.GetBool("profile_background_tile");
            ProfileBannerUrl               = user.GetString("profile_banner_url");
            StatusesCount                  = user.GetInt("statuses_count");
            Notifications                  = user.GetBool("notifications");
            GeoEnabled                     = user.GetBool("geo_enabled");
            Verified                       = user.GetBool("verified");
            ContributorsEnabled            = user.GetBool("contributors_enabled");
            Following                      = user.GetBool("following");
            ShowAllInlineMedia             = user.GetBool("show_all_inline_media");
            ListedCount                    = user.GetInt("listed_count");
            FollowRequestSent              = user.GetBool("follow_request_sent");
            user.TryGetProperty("status", out JsonElement statusElement);
            Status         = new Status(statusElement);
            CursorMovement = new Cursors(user);
            Email          = user.GetString("email");
        }
Пример #5
0
        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>();
        }