コード例 #1
0
        public RelatedResults(JsonData resultsJson)
        {
            if (resultsJson == null) return;

            ResultAnnotations = new Annotation(resultsJson.GetValue<JsonData>("annotations"));
            Score = resultsJson.GetValue<double>("score");
            Kind = resultsJson.GetValue<string>("kind");
            JsonData value = resultsJson.GetValue<JsonData>("value");
            ValueAnnotations = new Annotation(value.GetValue<JsonData>("annotations"));
            Retweeted = value.GetValue<bool>("retweeted");
            InReplyToScreenName = value.GetValue<string>("in_reply_to_screen_name");
            var contributors = value.GetValue<JsonData>("contributors");
            Contributors =
                contributors == null ?
                    new List<Contributor>() :
                    (from JsonData contributor in contributors
                     select new Contributor(contributor))
                    .ToList();
            Coordinates = new Coordinate(value.GetValue<JsonData>("coordinates"));
            Place = new Place(value.GetValue<JsonData>("place"));
            User = new User(value.GetValue<JsonData>("user"));
            RetweetCount = value.GetValue<int>("retweet_count");
            IDString = value.GetValue<string>("id_str");
            InReplyToUserID = value.GetValue<ulong>("in_reply_to_user_id");
            Favorited = value.GetValue<bool>("favorited");
            InReplyToStatusIDString = value.GetValue<string>("in_reply_to_status_id_str");
            InReplyToStatusID = value.GetValue<ulong>("in_reply_to_status_id");
            Source = value.GetValue<string>("source");
            CreatedAt = value.GetValue<string>("created_at").GetDate(DateTime.MaxValue);
            InReplyToUserIDString = value.GetValue<string>("in_reply_to_user_id_str");
            Truncated = value.GetValue<bool>("truncated");
            Geo = new Geo(value.GetValue<JsonData>("geo"));
            Text = value.GetValue<string>("text");
        }
コード例 #2
0
ファイル: Event.cs プロジェクト: prog-moh/LinqToTwitter
 public Event(JsonData evt)
 {
     Target = new User(evt.GetValue<JsonData>("target"));
     Source = new User(evt.GetValue<JsonData>("source"));
     EventName = evt.GetValue<string>("event");
     var targetObj = evt.GetValue<JsonData>("target_object", defaultValue: null);
     TargetObject = targetObj == null ? (string)null : targetObj.ToString();
     CreatedAt = evt.GetValue<string>("created_at").GetDate(DateTime.MaxValue);
 }
コード例 #3
0
ファイル: Tweep.cs プロジェクト: vishalishere/postworthy
 public Tweep(LinqToTwitter.User user, TweepType type)
 {
     User = new User(user);
     if (type == TweepType.Follower && user.Following)
     {
         Type = TweepType.Mutual;
     }
     else
     {
         Type = type;
     }
 }
コード例 #4
0
ファイル: DGUser.cs プロジェクト: giacomelli/DG.TwitterClient
        public static DGUser GetUser(User user)
        {
            DGUser dg = m_users.FirstOrDefault(u => u.Identifier.ScreenName.Equals(user.Identifier.ScreenName, StringComparison.OrdinalIgnoreCase));

            if (dg == null)
            {
                dg = new DGUser(user);
                m_users.Add(dg);
            }

            return dg;
        }
コード例 #5
0
 public DirectMessage(JsonData dmJson)
 {
     CreatedAt = dmJson.GetValue<string>("created_at").GetDate(DateTime.MinValue);
     SenderID = dmJson.GetValue<ulong>("sender_id");
     SenderScreenName = dmJson.GetValue<string>("sender_screen_name");
     Sender = new User(dmJson.GetValue<JsonData>("sender"));
     RecipientID = dmJson.GetValue<ulong>("recipient_id");
     RecipientScreenName = dmJson.GetValue<string>("recipient_screen_name");
     Recipient = new User(dmJson.GetValue<JsonData>("recipient"));
     IDResponse = dmJson.GetValue<ulong>("id");
     IDString = dmJson.GetValue<string>("id_str");
     Text = dmJson.GetValue<string>("text");
     Entities = new Entities(dmJson.GetValue<JsonData>("entities"));
 }
コード例 #6
0
        private async Task <SocialModel> GetTwitterData()
        {
            SocialModel model   = new SocialModel();
            var         account = AccountStore.Create().FindAccountsForService(AccountServiceTwitter).FirstOrDefault();
            var         auth    = new LinqToTwitter.SingleUserAuthorizer
            {
                CredentialStore = new SingleUserInMemoryCredentialStore
                {
                    ConsumerKey       = "FWinTbxeDRfqL6pd6TyvBWqvY",
                    ConsumerSecret    = "vqHOpCafR8eNNy140xfNRy80W2zyN0A4whM9lcVWj9oSPalDAz",
                    AccessToken       = account.Properties["oauth_token"],
                    AccessTokenSecret = account.Properties["oauth_token_secret"],
                }
            };

            var twitterCtx = new LinqToTwitter.TwitterContext(auth);

            try
            {
                var verifyResponse =
                    await
                        (from acct in twitterCtx.Account
                        where acct.Type == LinqToTwitter.AccountType.VerifyCredentials && (acct.IncludeEmail == true)
                        select acct)
                    .SingleOrDefaultAsync();

                if (verifyResponse != null && verifyResponse.User != null)
                {
                    LinqToTwitter.User user = verifyResponse.User;
                    model.Email     = user.Email;
                    model.Id        = user.UserIDResponse;
                    model.AvatarUrl = user.ProfileImageUrl.Replace("normal", "bigger");
                    model.AuthType  = AuthType.Twitter;
                    if (!String.IsNullOrEmpty(user.Name))
                    {
                        model.Name = user.Name;
                    }
                    else if (!String.IsNullOrEmpty(user.ScreenNameResponse))
                    {
                        model.Name = user.ScreenNameResponse;
                    }
                    return(model);
                }
            }
            catch (LinqToTwitter.TwitterQueryException)
            {
            }

            return(model);
        }
コード例 #7
0
        public void User_Can_Serialize()
        {
            var user = new User();
            var stringBuilder = new StringBuilder();

            var writer = XmlWriter.Create(stringBuilder);
            var xmlSerializer = new XmlSerializer(typeof(User));
            xmlSerializer.Serialize(writer, user);
        }
コード例 #8
0
ファイル: Status.cs プロジェクト: prog-moh/LinqToTwitter
        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;
            }
        }
コード例 #9
0
 void VerifySingleUserResponse(User user)
 {
     Assert.IsNotNull(user);
     Assert.IsNotNull(user.BannerSizes);
     Assert.IsFalse(user.BannerSizes.Any());
     Assert.IsNotNull(user.Categories);
     Assert.IsFalse(user.Categories.Any());
     Assert.AreEqual("6253282", user.UserIDResponse);
     Assert.AreEqual("twitterapi", user.ScreenNameResponse);
     Assert.AreEqual("San Francisco, CA", user.Location);
     Assert.IsNotNull(user.Description);
     Assert.IsTrue(user.Description.StartsWith("The Real Twitter API."));
     Assert.AreEqual("http://dev.twitter.com", user.Url);
     Assert.IsFalse(user.Protected);
     Assert.AreEqual(1009508, user.FollowersCount);
     Assert.AreEqual(31, user.FriendsCount);
     Assert.AreEqual(10361, user.ListedCount);
     Assert.AreEqual(new DateTime(2007, 5, 23, 6, 1, 13), user.CreatedAt);
     Assert.AreEqual(24, user.FavoritesCount);
     Assert.AreEqual(-28800, user.UtcOffset);
     Assert.AreEqual("Pacific Time (US & Canada)", user.TimeZone);
     Assert.IsTrue(user.GeoEnabled);
     Assert.IsTrue(user.Verified);
     Assert.AreEqual(3278, user.StatusesCount);
     Assert.AreEqual("en", user.LangResponse);
     var status = user.Status;
     Assert.IsNotNull(status);
     Assert.AreEqual("web", status.Source);
     var contributors = status.Contributors;
     Assert.IsNotNull(contributors);
     Assert.IsTrue(contributors.Any());
     var contributor = contributors.First();
     Assert.IsNotNull(contributor);
     Assert.IsTrue(user.ContributorsEnabled);
     Assert.IsFalse(user.IsTranslator);
     Assert.AreEqual("E8F2F7", user.ProfileBackgroundColor);
     Assert.AreEqual("http://a0.twimg.com/profile_background_images/229557229/twitterapi-bg.png", user.ProfileBackgroundImageUrl);
     Assert.AreEqual("https://si0.twimg.com/profile_background_images/229557229/twitterapi-bg.png", user.ProfileBackgroundImageUrlHttps);
     Assert.IsFalse(user.ProfileBackgroundTile);
     Assert.AreEqual("http://a0.twimg.com/profile_images/1438634086/avatar_normal.png", user.ProfileImageUrl);
     Assert.AreEqual("https://si0.twimg.com/profile_images/1438634086/avatar_normal.png", user.ProfileImageUrlHttps);
     Assert.AreEqual("0094C2", user.ProfileLinkColor);
     Assert.AreEqual("0094C2", user.ProfileSidebarBorderColor);
     Assert.AreEqual("A9D9F1", user.ProfileSidebarFillColor);
     Assert.AreEqual("437792", user.ProfileTextColor);
     Assert.IsTrue(user.ProfileUseBackgroundImage);
     Assert.IsFalse(user.ShowAllInlineMedia);
     Assert.IsFalse(user.DefaultProfile);
     Assert.IsFalse(user.DefaultProfileImage);
     Assert.IsFalse(user.Following);
     Assert.IsFalse(user.FollowRequestSent);
     Assert.IsFalse(user.Notifications);
 }
コード例 #10
0
ファイル: Status.cs プロジェクト: giggio/tweetercloud
        /// <summary>
        /// Shreds an XML element into a Status object
        /// </summary>
        /// <param name="status">XML element with info</param>
        /// <returns>Newly populated status object</returns>
        public Status CreateStatus(XElement status)
        {
            if (status == null)
            {
                return null;
            }

            var dateParts =
                status.Element("created_at").Value.Split(' ');

            var createdAtDate =
                dateParts.Count() > 1 ?
                DateTime.Parse(
                    string.Format("{0} {1} {2} {3} GMT",
                    dateParts[1],
                    dateParts[2],
                    dateParts[5],
                    dateParts[3]),
                    CultureInfo.InvariantCulture) :
                DateTime.MinValue;

            var user = status.Element("user");

            var retweet = status.Element("retweeted_status");

            var rtDateParts =
                retweet == null ?
                    null :
                    retweet.Element("created_at").Value.Split(' ');

            var retweetedAtDate =
                retweet == null ?
                    DateTime.MinValue :
                    DateTime.Parse(
                        string.Format("{0} {1} {2} {3} GMT",
                        rtDateParts[1],
                        rtDateParts[2],
                        rtDateParts[5],
                        rtDateParts[3]),
                        CultureInfo.InvariantCulture);

            List<string> contributorIDs = null;

            if (status.Element("contributors") != null)
            {
                contributorIDs =
                    (from id in status.Element("contributors").Elements("user_id")
                     select id.Value)
                     .ToList();
            }

            XNamespace geoRss = "http://www.georss.org/georss";

            var geoStr =
               status.Element("geo") != null &&
               status.Element("geo").Element(geoRss + "point") != null ?
                   status.Element("geo").Element(geoRss + "point").Value :
                   string.Empty;

            Geo geo = new Geo();
            if (!string.IsNullOrEmpty(geoStr))
            {
                var coordArr = geoStr.Split(' ');

                double tempLatitude = 0;
                double tempLongitide = 0;

                if (double.TryParse(coordArr[Coordinate.LatitudePos], out tempLatitude) &&
                    double.TryParse(coordArr[Coordinate.LongitudePos], out tempLongitide))
                {
                    geo =
                        new Geo
                        {
                            Latitude = tempLatitude,
                            Longitude = tempLongitide
                        };
                }
            }

            var coordStr =
                status.Element("coordinates") != null &&
                status.Element("coordinates").Element(geoRss + "point") != null ?
                    status.Element("coordinates").Element(geoRss + "point").Value :
                    string.Empty;

            Coordinate coord = new Coordinate();
            if (!string.IsNullOrEmpty(coordStr))
            {
                var coordArr = coordStr.Split(' ');

                double tempLatitude = 0;
                double tempLongitide = 0;

                if (double.TryParse(coordArr[Coordinate.LatitudePos], out tempLatitude) &&
                    double.TryParse(coordArr[Coordinate.LongitudePos], out tempLongitide))
                {
                    coord =
                        new Coordinate
                        {
                            Latitude = tempLatitude,
                            Longitude = tempLongitide
                        };
                }
            }

            var place = new Place().CreatePlace(status.Element("place"));

            var usr = new User();

            var newStatus = new Status
            {
                CreatedAt = createdAtDate,
                Favorited =
                 bool.Parse(
                     string.IsNullOrEmpty(status.Element("favorited").Value) ?
                     "true" :
                     status.Element("favorited").Value),
                StatusID = status.Element("id").Value,
                InReplyToStatusID = status.Element("in_reply_to_status_id").Value,
                InReplyToUserID = status.Element("in_reply_to_user_id").Value,
                Source = status.Element("source").Value,
                Text = status.Element("text").Value,
                Truncated = bool.Parse(status.Element("truncated").Value),
                InReplyToScreenName =
                     status.Element("in_reply_to_screen_name") == null ?
                         string.Empty :
                         status.Element("in_reply_to_screen_name").Value,
                ContributorIDs = contributorIDs,
                Geo = geo,
                Coordinates = coord,
                Place = place,
                User = usr.CreateUser(user),
                Retweet =
                    retweet == null ?
                        null :
                        new Retweet
                        {
                            ID = retweet.Element("id").Value,
                            CreatedAt = retweetedAtDate,
                            Favorited =
                                bool.Parse(
                                    string.IsNullOrEmpty(retweet.Element("favorited").Value) ?
                                    "true" :
                                    retweet.Element("favorited").Value),
                            InReplyToScreenName = retweet.Element("in_reply_to_screen_name").Value,
                            InReplyToStatusID = retweet.Element("in_reply_to_status_id").Value,
                            InReplyToUserID = retweet.Element("in_reply_to_user_id").Value,
                            Source = retweet.Element("source").Value,
                            Text = retweet.Element("text").Value,
                            Truncated =
                                bool.Parse(
                                    string.IsNullOrEmpty(retweet.Element("truncated").Value) ?
                                    "true" :
                                    retweet.Element("truncated").Value),
                            RetweetingUser = usr.CreateUser(retweet.Element("user"))
                        }
            };

            return newStatus;
        }
コード例 #11
0
ファイル: Commands.cs プロジェクト: azyobuzin/AAafeen
 private static string CreateUserText(User source)
 {
     if (source.Status != null)
         source.Status.User = source;
     return string.Format(@"ID:{0}
     Name:{1} / {2}
     Location:{3}
     Description:{4}
     CreatedAt:{5}
     WebSite:{6}
     Statuses:{7}
     Friends:{8}
     Followers:{9}
     FavCount:{10}
     {11}{12}{13}",
         source.Identifier.UserID,
         source.Identifier.ScreenName,
         source.Name,
         source.Location,
         source.Description,
         source.CreatedAt.ToLocalTime(),
         source.URL,
         source.StatusesCount,
         source.FriendsCount,
         source.FollowersCount,
         source.FavoritesCount,
         source.Verified ? "Verified" : "",
         source.Protected ? "Protected" : "",
         source.Status == null ? "" :
         string.Format("LastTweet\n\t{0}",
             string.Join("\n\t", CreateStatusText(source.Status).Split('\n'))
         )
     );
 }
コード例 #12
0
ファイル: User.cs プロジェクト: RuaanV/MyTwit
        /// <summary>
        /// creates a new user based on an XML user fragment
        /// </summary>
        /// <param name="user">XML user fragment</param>
        /// <returns>new User instance</returns>
        public static User CreateUser(XElement user)
        {
            if (user == null)
            {
                return null;
            }

            var tempUserProtected = false;
            var tempFollowersCount = 0ul;
            var tempFriendsCount = 0ul;
            var tempFavoritesCount = 0ul;
            var tempStatusesCount = 0ul;
            var tempFollowingUsers = false;
            var tempShowInlineMedia = false;
            var tempListedCount = 0;
            var tempFollowRequestSent = false;

            var canParseProtected =
                user.Element("protected") == null ?
                    false :
                    bool.TryParse(user.Element("protected").Value, out tempUserProtected);

            var followersCount =
                user.Element("followers_count") == null ?
                    false :
                    ulong.TryParse(user.Element("followers_count").Value, out tempFollowersCount);

            var friendsCount =
                user.Element("friends_count") == null ?
                    false :
                    ulong.TryParse(user.Element("friends_count").Value, out tempFriendsCount);

            var userDate = user.Element("created_at").Value;
            var userCreatedAtDate = String.IsNullOrEmpty(userDate) ?
                    DateTime.MinValue :
                    DateTime.ParseExact(
                        userDate,
                        "ddd MMM dd HH:mm:ss %zzzz yyyy",
                        CultureInfo.InvariantCulture,
                        DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);

            var favoritesCount =
                user.Element("favourites_count") == null ?
                    false :
                    ulong.TryParse(user.Element("favourites_count").Value, out tempFavoritesCount);

            var statusesCount =
                user.Element("statuses_count") == null ?
                    false :
                    ulong.TryParse(user.Element("statuses_count").Value, out tempStatusesCount);

            var notifications =
                user.Element("notifications") == null ||
                string.IsNullOrEmpty(user.Element("notifications").Value) ?
                    false :
                    bool.Parse(user.Element("notifications").Value);

            var geoEnabled =
                user.Element("geo_enabled") == null ||
                string.IsNullOrEmpty(user.Element("geo_enabled").Value) ?
                    false :
                    bool.Parse(user.Element("geo_enabled").Value);

            var verified =
                user.Element("verified") == null ||
                string.IsNullOrEmpty(user.Element("verified").Value) ?
                    false :
                    bool.Parse(user.Element("verified").Value);

            var contributorsEnabled =
                user.Element("contributors_enabled") == null ||
                string.IsNullOrEmpty(user.Element("contributors_enabled").Value) ?
                    false :
                    bool.Parse(user.Element("contributors_enabled").Value);

            var isFollowing =
                user.Element("following") == null ||
                string.IsNullOrEmpty(user.Element("following").Value) ?
                    false :
                    bool.TryParse(user.Element("following").Value, out tempFollowingUsers);

            var showInlineMedia =
                user.Element("show_all_inline_media") == null ?
                    false :
                    bool.TryParse(user.Element("show_all_inline_media").Value, out tempShowInlineMedia);

            var listedCount =
                user.Element("listed_count") == null ?
                    false :
                    int.TryParse(user.Element("listed_count").Value, out tempListedCount);

            var followRequestSent =
                user.Element("follow_request_sent") == null ?
                    false :
                    bool.TryParse(user.Element("follow_request_sent").Value, out tempFollowRequestSent);

            var status =
                user.Element("status");

            var newUser = new User
            {
                Identifier = new UserIdentifier
                {
                    ID = user.Element("id") == null ? "0" : user.Element("id").Value,
                    UserID = user.Element("id") == null ? "0" : user.Element("id").Value,
                    ScreenName = user.Element("screen_name") == null ? "" : user.Element("screen_name").Value
                },
                Name = user.Element("name") == null ? "" : user.Element("name").Value,
                Location = user.Element("location") == null ? "" : user.Element("location").Value,
                Description = user.Element("description") == null ? "" : user.Element("description").Value,
                ProfileImageUrl = user.Element("profile_image_url") == null ? "" : user.Element("profile_image_url").Value,
                URL = user.Element("url") == null ? "" : user.Element("url").Value,
                Protected = tempUserProtected,
                FollowersCount = tempFollowersCount,
                ProfileBackgroundColor =
                    user.Element("profile_background_color") == null ?
                        string.Empty :
                        user.Element("profile_background_color").Value,
                ProfileTextColor =
                    user.Element("profile_text_color") == null ?
                        string.Empty :
                        user.Element("profile_text_color").Value,
                ProfileLinkColor =
                    user.Element("profile_link_color") == null ?
                        string.Empty :
                        user.Element("profile_link_color").Value,
                ProfileSidebarFillColor =
                    user.Element("profile_sidebar_fill_color") == null ?
                        string.Empty :
                        user.Element("profile_sidebar_fill_color").Value,
                ProfileSidebarBorderColor =
                    user.Element("profile_sidebar_border_color") == null ?
                        string.Empty :
                        user.Element("profile_sidebar_border_color").Value,
                FriendsCount = tempFriendsCount,
                CreatedAt = userCreatedAtDate,
                FavoritesCount = tempFavoritesCount,
                UtcOffset =
                    user.Element("utc_offset") == null ?
                        string.Empty :
                        user.Element("utc_offset").Value,
                TimeZone =
                    user.Element("time_zone") == null ?
                        string.Empty :
                        user.Element("time_zone").Value,
                ProfileBackgroundImageUrl =
                    user.Element("profile_background_image_url") == null ?
                        string.Empty :
                        user.Element("profile_background_image_url").Value,
                ProfileBackgroundTile =
                    user.Element("profile_background_tile") == null ?
                        string.Empty :
                        user.Element("profile_background_tile").Value,
                StatusesCount = tempStatusesCount,
                Notifications = notifications,
                GeoEnabled = geoEnabled,
                Verified = verified,
                ContributorsEnabled = contributorsEnabled,
                Following = tempFollowingUsers,
                ShowAllInlineMedia = tempShowInlineMedia,
                ListedCount = tempListedCount,
                FollowRequestSent = tempFollowRequestSent,
                Status = Status.CreateStatus(status),
                CursorMovement = Cursors.CreateCursors(GrandParentOrNull(user))
            };

            return newUser;
        }
コード例 #13
0
ファイル: User.cs プロジェクト: giggio/tweetercloud
        /// <summary>
        /// creates a new user based on an XML user fragment
        /// </summary>
        /// <param name="user">XML user fragment</param>
        /// <returns>new User instance</returns>
        public User CreateUser(XElement user)
        {
            if (user == null)
            {
                return null;
            }

            var tempUserProtected = false;
            var tempFollowersCount = 0ul;
            var tempFriendsCount = 0ul;
            var tempFavoritesCount = 0ul;
            var tempStatusesCount = 0ul;
            var tempStatusTruncated = false;
            var tempStatusFavorited = false;
            var tempFollowingUsers = false;

            var canParseProtected =
                bool.TryParse(user.Element("protected").Value, out tempUserProtected);

            var followersCount =
                ulong.TryParse(user.Element("followers_count").Value, out tempFollowersCount);

            var friendsCount =
                user.Element("friends_count") == null ?
                    false :
                    ulong.TryParse(user.Element("friends_count").Value, out tempFriendsCount);

            var userDateParts =
                user.Element("created_at") == null ?
                    null :
                    user.Element("created_at").Value.Split(' ');

            var userCreatedAtDate =
                userDateParts == null ?
                    DateTime.MinValue :
                    DateTime.Parse(
                        string.Format("{0} {1} {2} {3} GMT",
                        userDateParts[1],
                        userDateParts[2],
                        userDateParts[5],
                        userDateParts[3]),
                        CultureInfo.InvariantCulture);

            var favoritesCount =
                user.Element("favourites_count") == null ?
                    false :
                    ulong.TryParse(user.Element("favourites_count").Value, out tempFavoritesCount);

            var statusesCount =
                user.Element("statuses_count") == null ?
                    false :
                    ulong.TryParse(user.Element("statuses_count").Value, out tempStatusesCount);

            var notifications =
                user.Element("notifications") == null ||
                string.IsNullOrEmpty(user.Element("notifications").Value) ?
                    false :
                    bool.Parse(user.Element("notifications").Value);

            var geoEnabled =
                user.Element("geo_enabled") == null ||
                string.IsNullOrEmpty(user.Element("geo_enabled").Value) ?
                    false :
                    bool.Parse(user.Element("geo_enabled").Value);

            var verified =
                user.Element("verified") == null ||
                string.IsNullOrEmpty(user.Element("verified").Value) ?
                    false :
                    bool.Parse(user.Element("verified").Value);

            var contributorsEnabled =
                user.Element("contributors_enabled") == null ||
                string.IsNullOrEmpty(user.Element("contributors_enabled").Value) ?
                    false :
                    bool.Parse(user.Element("contributors_enabled").Value);

            var isFollowing =
                user.Element("following") == null ||
                string.IsNullOrEmpty(user.Element("following").Value) ?
                    false :
                    bool.TryParse(user.Element("following").Value, out tempFollowingUsers);

            var status =
                user.Element("status");

            var statusDateParts =
                status == null ?
                    null :
                    status.Element("created_at").Value.Split(' ');

            var statusCreatedAtDate =
                statusDateParts == null ?
                    DateTime.MinValue :
                    DateTime.Parse(
                        string.Format("{0} {1} {2} {3} GMT",
                        statusDateParts[1],
                        statusDateParts[2],
                        statusDateParts[5],
                        statusDateParts[3]),
                        CultureInfo.InvariantCulture);

            var newUser = new User
            {
                Identifier = new UserIdentifier
                {
                    ID = user.Element("id").Value,
                    UserID = user.Element("id").Value,
                    ScreenName = user.Element("screen_name").Value
                },
                Name = user.Element("name").Value,
                Location = user.Element("location").Value,
                Description = user.Element("description").Value,
                ProfileImageUrl = user.Element("profile_image_url").Value,
                URL = user.Element("url").Value,
                Protected = tempUserProtected,
                FollowersCount = tempFollowersCount,
                ProfileBackgroundColor =
                    user.Element("profile_background_color") == null ?
                        string.Empty :
                        user.Element("profile_background_color").Value,
                ProfileTextColor =
                    user.Element("profile_text_color") == null ?
                        string.Empty :
                        user.Element("profile_text_color").Value,
                ProfileLinkColor =
                    user.Element("profile_link_color") == null ?
                        string.Empty :
                        user.Element("profile_link_color").Value,
                ProfileSidebarFillColor =
                    user.Element("profile_sidebar_fill_color") == null ?
                        string.Empty :
                        user.Element("profile_sidebar_fill_color").Value,
                ProfileSidebarBorderColor =
                    user.Element("profile_sidebar_border_color") == null ?
                        string.Empty :
                        user.Element("profile_sidebar_border_color").Value,
                FriendsCount = tempFriendsCount,
                CreatedAt = userCreatedAtDate,
                FavoritesCount = tempFavoritesCount,
                UtcOffset =
                    user.Element("utc_offset") == null ?
                        string.Empty :
                        user.Element("utc_offset").Value,
                TimeZone =
                    user.Element("time_zone") == null ?
                        string.Empty :
                        user.Element("time_zone").Value,
                ProfileBackgroundImageUrl =
                    user.Element("profile_background_image_url") == null ?
                        string.Empty :
                        user.Element("profile_background_image_url").Value,
                ProfileBackgroundTile =
                    user.Element("profile_background_tile") == null ?
                        string.Empty :
                        user.Element("profile_background_tile").Value,
                StatusesCount = tempStatusesCount,
                Notifications = notifications,
                GeoEnabled = geoEnabled,
                Verified = verified,
                ContributorsEnabled = contributorsEnabled,
                Following = tempFollowingUsers,
                Status = // TODO: refactor to CreateStatus
                    status == null ?
                        null :
                        new Status
                        {
                            CreatedAt = statusCreatedAtDate,
                            ID = status.Element("id").Value,
                            Text = status.Element("text").Value,
                            Source = status.Element("source").Value,
                            Truncated = tempStatusTruncated,
                            InReplyToStatusID = status.Element("in_reply_to_status_id").Value,
                            InReplyToUserID = status.Element("in_reply_to_user_id").Value,
                            Favorited = tempStatusFavorited,
                            InReplyToScreenName = status.Element("in_reply_to_screen_name").Value
                        },
                CursorMovement = new Cursors()
                {
                    Next =
                            (user.Parent == null || user.Parent.Parent == null || user.Parent.Parent.Element("next_cursor") == null) ?
                                string.Empty :
                                user.Parent.Parent.Element("next_cursor").Value,
                    Previous =
                            (user.Parent == null || user.Parent.Parent == null || user.Parent.Parent.Element("previous_cursor") == null) ?
                                string.Empty :
                                user.Parent.Parent.Element("previous_cursor").Value
                }
            };

            return newUser;
        }
コード例 #14
0
ファイル: UserTest.cs プロジェクト: giggio/tweetercloud
        public void CreateUserTest()
        {
            User target = new User();
            XElement user = XElement.Parse(m_userXml);
            User expected = new User()
            {
                 CreatedAt = new DateTime(2008, 7, 13, 4, 35, 50),
                 Description = "Created LINQ to Twitter, author of LINQ Programming/McGraw-Hill, .NET Consulting, and Microsoft MVP",
                 Name = "Joe Mayo",
                 Following = false
            };

            User actual = target.CreateUser(user);
            Assert.AreEqual(expected.Description, actual.Description);
            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.Following, actual.Following);
        }
コード例 #15
0
ファイル: UserTest.cs プロジェクト: giggio/tweetercloud
 public void CreateNullUserTest()
 {
     User actual = new User().CreateUser(null);
     Assert.IsNull(actual);
 }
コード例 #16
0
ファイル: DGUser.cs プロジェクト: giacomelli/DG.TwitterClient
 private DGUser(User source)
 {
     Source = source;
     m_visible = true;
 }