OSDN Git Service

HttpTwitter.SendDirectMessageメソッドをTwitterApiクラスに置き換え
[opentween/open-tween.git] / OpenTween / Connection / TwitterPhoto.cs
index 5bde80a..363beb2 100644 (file)
@@ -30,7 +30,7 @@ using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Threading.Tasks;
-using OpenTween.Api;
+using OpenTween.Api.DataModel;
 
 namespace OpenTween.Connection
 {
@@ -62,7 +62,7 @@ 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)
@@ -76,31 +76,24 @@ namespace OpenTween.Connection
             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");
-
-                mediaFiles.Add(mediaFile);
+                if (!item.Exists)
+                    throw new ArgumentException("Err:Media not found.");
             }
 
-            await Task.Run(() =>
-                {
-                    var res = this.tw.PostStatusWithMultipleMedia(text, inReplyToStatusId, mediaFiles);
-                    if (!string.IsNullOrEmpty(res))
-                        throw new WebApiException(res);
-                })
+            await this.tw.PostStatusWithMultipleMedia(text, inReplyToStatusId, mediaItems)
                 .ConfigureAwait(false);
         }