using System.IO;
using System.Linq;
using System.Threading.Tasks;
-using OpenTween.Api;
+using OpenTween.Api.DataModel;
namespace OpenTween.Connection
{
public bool CheckFileExtension(string fileExtension)
{
- return this.pictureExt.Contains(fileExtension.ToLower());
+ return this.pictureExt.Contains(fileExtension.ToLowerInvariant());
}
public bool CheckFileSize(string fileExtension, long fileSize)
return this.twitterConfig.PhotoSizeLimit;
}
- public async Task PostStatusAsync(string text, long? inReplyToStatusId, string[] filePaths)
+ public async Task PostStatusAsync(string text, long? inReplyToStatusId, IMediaItem[] mediaItems)
{
- if (filePaths == null || filePaths.Length == 0 || string.IsNullOrEmpty(filePaths[0]))
- throw new ArgumentException("Err:File isn't specified.", "filePaths");
+ if (mediaItems == null)
+ throw new ArgumentNullException(nameof(mediaItems));
- var mediaFiles = new List<FileInfo>();
+ if (mediaItems.Length == 0)
+ throw new ArgumentException("Err:Media not specified.");
- foreach (var filePath in filePaths)
+ foreach (var item in mediaItems)
{
- if (string.IsNullOrEmpty(filePath)) continue;
+ if (item == null)
+ throw new ArgumentException("Err:Media not specified.");
- var mediaFile = new FileInfo(filePath);
-
- if (!mediaFile.Exists)
- throw new ArgumentException("Err:File isn't exists.", "filePaths");
-
- if (MyCommon.IsAnimatedGif(filePath))
- throw new ArgumentException("Err:Don't support animatedGIF.", "filePaths");
-
- mediaFiles.Add(mediaFile);
+ if (!item.Exists)
+ throw new ArgumentException("Err:Media not found.");
}
- await Task.Run(() => this.tw.PostStatusWithMultipleMedia(text, inReplyToStatusId, mediaFiles))
+ await this.tw.PostStatusWithMultipleMedia(text, inReplyToStatusId, mediaItems)
.ConfigureAwait(false);
}