コード例 #1
0
        /// <summary>
        /// Initializes a new instance based on the specified <paramref name="obj"/>.
        /// </summary>
        /// <param name="obj">The instance of <see cref="JObject"/> representing the status message.</param>
        protected TwitterStatusMessage(JObject obj) : base(obj)
        {
            // Parse basic properties
            Id          = obj.GetInt64("id");
            Text        = obj.GetString("text");
            Source      = obj.GetString("source");
            IsTruncated = obj.GetBoolean("truncated");

            // Twitter has some strange date formats
            CreatedAt = obj.GetString("created_at", TwitterUtils.ParseDateTimeUtc);

            // Parse the reply information
            if (obj.HasValue("in_reply_to_status_id"))
            {
                InReplyTo = new TwitterReplyTo {
                    StatusId    = obj.GetInt64("in_reply_to_status_id"),
                    StatusIdStr = obj.GetString("in_reply_to_status_id_str"),
                    UserId      = obj.GetInt64("in_reply_to_user_id"),
                    UserIdStr   = obj.GetString("in_reply_to_user_id_str"),
                    ScreenName  = obj.GetString("in_reply_to_screen_name")
                };
            }

            RetweetCount  = obj.GetInt32("retweet_count");
            FavoriteCount = obj.GetInt32("favorite_count");

            // Related to the authenticating user
            HasFavorited = obj.GetBoolean("favorited");
            HasRetweeted = obj.GetBoolean("retweeted");

            // Parse the entities (if any)
            Entities = obj.GetObject("entities", TwitterStatusMessageEntities.Parse);

            ExtendedEntities = obj.GetObject("extended_entities", TwitterExtendedEntities.Parse);

            // For some weird reason Twitter flips the coordinates by writing longitude before latitude
            // See: https://dev.twitter.com/docs/platform-objects/tweets#obj-coordinates)
            Coordinates = obj.GetObject("coordinates", TwitterCoordinates.Parse);

            // See: https://dev.twitter.com/docs/platform-objects/tweets#obj-contributors

            /*if (tweet.contributors != null) {
             *  List<TwitterContributor> contributors = new List<TwitterContributor>();
             *  foreach (dynamic contributor in tweet.contributors) {
             *      contributors.Add(new TwitterContributor {
             *          UserId = contributor.id,
             *          ScreenName = contributor.screen_name
             *      });
             *  }
             *  msg.Contributors = contributors.ToArray();
             * }*/

            User  = obj.GetObject("user", TwitterUser.Parse);
            Place = obj.GetObject("place", TwitterPlace.Parse);

            IsPossiblyOffensive = obj.GetBoolean("possibly_sensitive");
            Language            = obj.GetString("lang");
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance based on the specified <paramref name="obj"/>.
        /// </summary>
        /// <param name="obj">The instance of <see cref="JObject"/> representing the status message.</param>
        protected TwitterStatusMessage(JObject obj) : base(obj)
        {
            // Parse basic properties
            Id          = obj.GetInt64("id");
            IdStr       = obj.GetString("id_str");
            Text        = obj.GetString("text");
            FullText    = obj.GetString("full_text");
            Source      = obj.GetString("source");
            IsTruncated = obj.GetBoolean("truncated");

            // Twitter has some strange date formats
            CreatedAt = obj.GetString("created_at", TwitterUtils.ParseDateTimeUtc);

            // Parse the reply information
            if (obj.HasValue("in_reply_to_status_id"))
            {
                InReplyTo = new TwitterReplyTo {
                    StatusId    = obj.GetInt64("in_reply_to_status_id"),
                    StatusIdStr = obj.GetString("in_reply_to_status_id_str"),
                    UserId      = obj.GetInt64("in_reply_to_user_id"),
                    UserIdStr   = obj.GetString("in_reply_to_user_id_str"),
                    ScreenName  = obj.GetString("in_reply_to_screen_name")
                };
            }

            User = obj.GetObject("user", TwitterUser.Parse);

            // For some weird reason Twitter flips the coordinates by writing longitude before latitude
            // See: https://dev.twitter.com/docs/platform-objects/tweets#obj-coordinates)
            Coordinates = obj.GetObject("coordinates", TwitterCoordinates.Parse);

            Place = obj.GetObject("place", TwitterPlace.Parse);

            // Parse quote information
            QuotedStatusId    = obj.GetInt64("quoted_status_id");
            QuotedStatusIdStr = obj.GetString("quoted_status_id_str");
            IsQuoteStatus     = obj.GetBoolean("is_quote_status");


            QuotedStatus    = obj.GetObject("quoted_status", Parse);
            RetweetedStatus = obj.GetObject("retweeted_status", Parse);

            QuoteCount    = obj.GetInt32("quote_count");
            ReplyCount    = obj.GetInt32("reply_count");
            RetweetCount  = obj.GetInt32("retweet_count");
            FavoriteCount = obj.GetInt32("favorite_count");

            // Parse the entities (if any)
            Entities         = obj.GetObject("entities", TwitterStatusMessageEntities.Parse);
            ExtendedEntities = obj.GetObject("extended_entities", TwitterExtendedEntities.Parse);

            // Related to the authenticating user
            HasFavorited = obj.GetBoolean("favorited");
            HasRetweeted = obj.GetBoolean("retweeted");

            // Misc
            IsPossiblyOffensive = obj.GetBoolean("possibly_sensitive");
            // TODO: Add support for the "filter_level" property
            Language = obj.GetString("lang");
            // TODO: Add support for the "matching_rules" property
        }