コード例 #1
0
        public static TwitterBoundingBox Parse(JsonObject obj)
        {
            // Check whether "obj" is NULL
            if (obj == null)
            {
                return(null);
            }

            // Get the array
            JsonArray coordinates = obj.GetArray("coordinates");

            // Initialize the bounding box
            TwitterBoundingBox boundingBox = new TwitterBoundingBox {
                Type        = obj.GetString("type"),
                Coordinates = new TwitterCoordinates[coordinates.Length][]
            };

            // Parse the coordinates
            for (int i = 0; i < coordinates.Length; i++)
            {
                boundingBox.Coordinates[i] = TwitterCoordinates.ParseMultiple(coordinates.GetArray(i));
            }

            // Return the building box
            return(boundingBox);
        }
コード例 #2
0
 public static TwitterCoordinates[] ParseMultiple(JsonArray array) {
     if (array == null) return new TwitterCoordinates[0];
     TwitterCoordinates[] temp = new TwitterCoordinates[array.Length];
     for (int i = 0; i < array.Length; i++) {
         temp[i] = Parse(array.GetArray(i));
     }
     return temp;
 }
コード例 #3
0
 public static TwitterCoordinates[] ParseMultiple(JsonArray array)
 {
     if (array == null)
     {
         return(new TwitterCoordinates[0]);
     }
     TwitterCoordinates[] temp = new TwitterCoordinates[array.Length];
     for (int i = 0; i < array.Length; i++)
     {
         temp[i] = Parse(array.GetArray(i));
     }
     return(temp);
 }
コード例 #4
0
        private TwitterBoundingBox(JObject obj) : base(obj)
        {
            // Get the array
            JArray coordinates = obj.GetArray("coordinates");

            // Initialize properties
            Type        = obj.GetString("type");
            Coordinates = new TwitterCoordinates[coordinates.Count][];

            // Parse the coordinates
            for (int i = 0; i < coordinates.Count; i++)
            {
                Coordinates[i] = TwitterCoordinates.ParseMultiple(coordinates.GetArray(i));
            }
        }
コード例 #5
0
        /// <summary>
        /// Gets a status message (tweet) from the specified <var>JsonObject</var>.
        /// </summary>
        /// <param name="obj">The instance of <var>JsonObject</var> to parse.</param>
        public static TwitterStatusMessage Parse(JsonObject obj)
        {
            // Error checking
            if (obj == null)
            {
                return(null);
            }
            if (obj.HasValue("error"))
            {
                throw TwitterException.Parse(obj.GetArray("error"));
            }
            if (obj.HasValue("errors"))
            {
                throw TwitterException.Parse(obj.GetArray("errors"));
            }

            TwitterStatusMessage msg = new TwitterStatusMessage(obj)
            {
                Id          = obj.GetInt64("id"),
                Text        = obj.GetString("text"),
                Source      = obj.GetString("source"),
                IsTruncated = obj.GetBoolean("truncated")
            };

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

            // Parse the reply information
            if (obj.HasValue("in_reply_to_status_id"))
            {
                msg.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")
                };
            }

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

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

            // Parse the entities (if any)
            msg.Entities = obj.GetObject("entities", TwitterStatusMessageEntities.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)
            msg.Coordinates = TwitterCoordinates.Parse(obj.GetObject("coordinates"));

            // 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();
             * }*/

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

            msg.IsPossiblyOffensive = obj.GetBoolean("possibly_sensitive");
            msg.Language            = obj.GetString("lang");

            return(msg);
        }