コード例 #1
0
        /// <summary>
        /// Reads a file from the disk and returns a <see cref="TwitterImage"/> instance for uploading.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <returns></returns>
        public static TwitterImage ReadFromDisk(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new ArgumentException(string.Format("File does not be exist: {0}.", filePath));
            }

            TwitterImage newImage = new TwitterImage();

            newImage.Data = File.ReadAllBytes(filePath);

            FileInfo imageFileInfo = new FileInfo(filePath);

            newImage.Filename = imageFileInfo.Name;

            switch (imageFileInfo.Extension.ToLower())
            {
            case ".jpg":
            case ".jpeg":
                newImage.ImageType = TwitterImageImageType.Jpeg;
                break;

            case ".gif":
                newImage.ImageType = TwitterImageImageType.Gif;
                break;

            case ".png":
                newImage.ImageType = TwitterImageImageType.PNG;
                break;

            default:
                throw new Exception("File is not a recognized type. Must be jpg, png, or gif.");
            }

            return(newImage);
        }
コード例 #2
0
 /// <summary>
 /// Updates the authenticating user's profile image.
 /// </summary>
 /// <param name="tokens">The tokens.</param>
 /// <param name="image">The avatar image for the profile. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down.</param>
 /// <returns>
 /// The user, with updated data, as a <see cref="TwitterUser"/>
 /// </returns>
 public static TwitterResponse<TwitterUser> UpdateProfileImage(OAuthTokens tokens, TwitterImage image)
 {
     return UpdateProfileImage(tokens, image, null);
 }
コード例 #3
0
        /// <summary>
        /// Updates the authenticating user's profile image. 
        /// </summary>
        /// <param name="tokens">The tokens.</param>
        /// <param name="image">The avatar image for the profile. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down.</param>
        /// <param name="options">The options.</param>
        /// <returns>
        /// The user, with updated data, as a <see cref="TwitterUser"/>
        /// </returns>
        public static TwitterResponse<TwitterUser> UpdateProfileImage(OAuthTokens tokens, TwitterImage image, OptionalProperties options)
        {
            Commands.UpdateProfileImageCommand command = new Twitterizer.Commands.UpdateProfileImageCommand(tokens, image, options);

            return CommandPerformer.PerformAction(command);
        }
コード例 #4
0
        /// <summary>
        /// Reads a file from the disk and returns a <see cref="TwitterImage"/> instance for uploading.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <returns></returns>
        public static TwitterImage ReadFromDisk(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new ArgumentException(string.Format("File does not be exist: {0}.", filePath));
            }

            TwitterImage newImage = new TwitterImage();
            newImage.Data = File.ReadAllBytes(filePath);

            FileInfo imageFileInfo = new FileInfo(filePath);
            newImage.Filename = imageFileInfo.Name;

            switch (imageFileInfo.Extension.ToLower())
            {
                case ".jpg":
                case ".jpeg":
                    newImage.ImageType = TwitterImageImageType.Jpeg;
                    break;
                case ".gif":
                    newImage.ImageType = TwitterImageImageType.Gif;
                    break;
                case ".png":
                    newImage.ImageType = TwitterImageImageType.PNG;
                    break;
                default:
                    throw new Exception("File is not a recognized type. Must be jpg, png, or gif.");
            }

            return newImage;
        }