Example #1
0
        /// <summary>
        /// Gets a user from the specified <var>JsonObject</var>.
        /// </summary>
        /// <param name="obj">The instance of <var>JsonObject</var> to parse.</param>
        public static TwitterUser Parse(JsonObject obj)
        {
            // Error checking
            if (obj == null)
            {
                return(null);
            }
            if (obj.HasValue("error"))
            {
                throw TwitterException.Parse(obj.GetArray("error"));
            }

            TwitterUser user = new TwitterUser(obj);

            #region Basic properties

            user.Id              = obj.GetInt64("id");
            user.IdStr           = obj.GetString("id_str");
            user.Name            = obj.GetString("name");
            user.ScreenName      = obj.GetString("screen_name");
            user.Location        = obj.GetString("location");
            user.Url             = obj.GetString("url");
            user.Description     = obj.GetString("description");
            user.IsProtected     = obj.GetBoolean("protected");
            user.FollowersCount  = obj.GetInt32("followers_count");
            user.FriendsCount    = obj.GetInt32("friends_count");
            user.ListedCount     = obj.GetInt32("listed_count");
            user.CreatedAt       = TwitterUtils.ParseDateTime(obj.GetString("created_at"));
            user.FavouritesCount = obj.GetInt32("favourites_count");
            if (obj.HasValue("utc_offset"))
            {
                user.UtcOffset = obj.GetInt32("utc_offset");
            }
            user.TimeZone            = obj.GetString("time_zone");
            user.IsGeoEnabled        = obj.GetBoolean("geo_enabled");
            user.IsVerified          = obj.GetBoolean("verified");
            user.StatusesCount       = obj.GetInt32("statuses_count");
            user.Language            = obj.GetString("lang");
            user.ContributorsEnabled = obj.GetBoolean("contributors_enabled");
            user.IsTranslator        = obj.GetBoolean("is_translator");
            user.FollowRequestSent   = obj.HasValue("follow_request_sent") && obj.GetBoolean("follow_request_sent");
            user.Status   = obj.GetObject("status", TwitterStatusMessage.Parse);
            user.Entities = obj.GetObject("entities", TwitterUserEntities.Parse);

            #endregion

            #region Profile properties

            user.HasDefaultProfile              = obj.GetBoolean("default_profile");
            user.HasDefaultProfileImage         = obj.GetBoolean("default_profile_image");
            user.ProfileBackgroundColor         = obj.GetString("profile_background_color");
            user.ProfileBackgroundImageUrl      = obj.GetString("profile_background_image_url");
            user.ProfileBackgroundImageUrlHttps = obj.GetString("profile_background_image_url_https");
            user.ProfileBackgroundTile          = obj.GetBoolean("profile_background_tile");
            user.ProfileBannerUrl          = obj.GetString("profile_banner_url");
            user.ProfileImageUrl           = obj.GetString("profile_image_url");
            user.ProfileImageUrlHttps      = obj.GetString("profile_image_url_https");
            user.ProfileLinkColor          = obj.GetString("profile_link_color");
            user.ProfileSidebarBorderColor = obj.GetString("profile_sidebar_border_color");
            user.ProfileSidebarFillColor   = obj.GetString("profile_sidebar_fill_color");
            user.ProfileTextColor          = obj.GetString("profile_text_color");
            user.ProfileUseBackgroundImage = obj.GetBoolean("profile_use_background_image");

            #endregion

            return(user);
        }
        /// <summary>
        /// Gets a user from the specified <var>JsonObject</var>.
        /// </summary>
        /// <param name="obj">The instance of <var>JsonObject</var> to parse.</param>
        public static TwitterUser Parse(JsonObject obj) {
            
            // Error checking
            if (obj == null) return null;
            if (obj.HasValue("error")) throw TwitterException.Parse(obj.GetArray("error"));
            
            TwitterUser user = new TwitterUser();

            #region Basic properties
            
            user.JsonObject = obj;
            user.Id = obj.GetLong("id");
            user.IdStr = obj.GetString("id_str");
            user.Name = obj.GetString("name");
            user.ScreenName = obj.GetString("screen_name");
            user.Location = obj.GetString("location");
            user.Url = obj.GetString("url");
            user.Description = obj.GetString("description");
            user.IsProtected = obj.GetBoolean("protected");
            user.FollowersCount = obj.GetInt("followers_count");
            user.FriendsCount = obj.GetInt("friends_count");
            user.ListedCount = obj.GetInt("listed_count");
            user.CreatedAt = TwitterUtils.ParseDateTime(obj.GetString("created_at"));
            user.FavouritesCount = obj.GetInt("favourites_count");
            if (obj.HasValue("utc_offset")) user.UtcOffset = obj.GetInt("utc_offset");
            user.TimeZone = obj.GetString("time_zone");
            user.IsGeoEnabled = obj.GetBoolean("geo_enabled");
            user.IsVerified = obj.GetBoolean("verified");
            user.StatusesCount = obj.GetInt("statuses_count");
            user.Language = obj.GetString("lang");
            user.ContributorsEnabled = obj.GetBoolean("contributors_enabled");
            user.IsTranslator = obj.GetBoolean("is_translator");
            user.IsFollowing = obj.HasValue("following") && obj.GetBoolean("following");
            user.FollowRequestSent = obj.HasValue("follow_request_sent") && obj.GetBoolean("follow_request_sent");
            user.Notifications = obj.HasValue("notifications") && obj.GetBoolean("notifications");
            user.Status = obj.GetObject("status", TwitterStatusMessage.Parse);
           
            #endregion

            #region Profile properties
            
            user.HasDefaultProfile = obj.GetBoolean("default_profile");
            user.HasDefaultProfileImage = obj.GetBoolean("default_profile_image");
            user.ProfileBackgroundColor = obj.GetString("profile_background_color");
            user.ProfileBackgroundImageUrl = obj.GetString("profile_background_image_url");
            user.ProfileBackgroundImageUrlHttps = obj.GetString("profile_background_image_url_https");
            user.ProfileBackgroundTile = obj.GetBoolean("profile_background_tile");
            user.ProfileBannerUrl = obj.GetString("profile_banner_url");
            user.ProfileImageUrl = obj.GetString("profile_image_url");
            user.ProfileImageUrlHttps = obj.GetString("profile_image_url_https");
            user.ProfileLinkColor = obj.GetString("profile_link_color");
            user.ProfileSidebarBorderColor = obj.GetString("profile_sidebar_border_color");
            user.ProfileSidebarFillColor = obj.GetString("profile_sidebar_fill_color");
            user.ProfileTextColor = obj.GetString("profile_text_color");
            user.ProfileUseBackgroundImage = obj.GetBoolean("profile_use_background_image");
            
            #endregion

            return user;

        }