OSDN Git Service

IMediaUploadService関連のクラスの名前空間を移動
authorKimura Youichi <kim.upsilon@bucyou.net>
Sat, 22 Jan 2022 02:03:51 +0000 (11:03 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 22 Jan 2022 07:09:31 +0000 (16:09 +0900)
OpenTween/Api/ImgurApi.cs [new file with mode: 0644]
OpenTween/Api/MobypictureApi.cs [new file with mode: 0644]
OpenTween/MediaSelector.cs
OpenTween/MediaUploadServices/IMediaUploadService.cs [moved from OpenTween/Connection/IMediaUploadService.cs with 98% similarity]
OpenTween/MediaUploadServices/Imgur.cs [moved from OpenTween/Connection/Imgur.cs with 72% similarity]
OpenTween/MediaUploadServices/Mobypicture.cs [moved from OpenTween/Connection/Mobypicture.cs with 65% similarity]
OpenTween/MediaUploadServices/TwitterPhoto.cs [moved from OpenTween/Connection/TwitterPhoto.cs with 99% similarity]
OpenTween/OpenTween.csproj
OpenTween/Tween.cs

diff --git a/OpenTween/Api/ImgurApi.cs b/OpenTween/Api/ImgurApi.cs
new file mode 100644 (file)
index 0000000..d5c39be
--- /dev/null
@@ -0,0 +1,80 @@
+// OpenTween - Client of Twitter
+// Copyright (c) 2013 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
+// All rights reserved.
+//
+// This file is part of OpenTween.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#nullable enable
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+using OpenTween.Connection;
+
+namespace OpenTween.Api
+{
+    public class ImgurApi
+    {
+        private readonly string clientId;
+        private readonly HttpClient http;
+
+        private static readonly Uri UploadEndpoint = new Uri("https://api.imgur.com/3/image.xml");
+
+        public ImgurApi()
+            : this(ApplicationSettings.ImgurClientID)
+        {
+        }
+
+        public ImgurApi(string clientId)
+        {
+            this.clientId = clientId;
+            this.http = Networking.CreateHttpClient(Networking.CreateHttpClientHandler());
+            this.http.Timeout = Networking.UploadImageTimeout;
+        }
+
+        public async Task<XDocument> UploadFileAsync(IMediaItem item, string title)
+        {
+            using var content = new MultipartFormDataContent();
+            using var mediaStream = item.OpenRead();
+            using var mediaContent = new StreamContent(mediaStream);
+            using var titleContent = new StringContent(title);
+
+            content.Add(mediaContent, "image", item.Name);
+            content.Add(titleContent, "title");
+
+            using var request = new HttpRequestMessage(HttpMethod.Post, UploadEndpoint);
+            request.Headers.Authorization = new AuthenticationHeaderValue("Client-ID", this.clientId);
+            request.Content = content;
+
+            using var response = await this.http.SendAsync(request)
+                .ConfigureAwait(false);
+
+            response.EnsureSuccessStatusCode();
+
+            using var stream = await response.Content.ReadAsStreamAsync()
+                .ConfigureAwait(false);
+
+            return XDocument.Load(stream);
+        }
+    }
+}
diff --git a/OpenTween/Api/MobypictureApi.cs b/OpenTween/Api/MobypictureApi.cs
new file mode 100644 (file)
index 0000000..7c286b1
--- /dev/null
@@ -0,0 +1,93 @@
+// OpenTween - Client of Twitter
+// Copyright (c) 2014 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
+// All rights reserved.
+//
+// This file is part of OpenTween.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#nullable enable
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+using OpenTween.Connection;
+
+namespace OpenTween.Api
+{
+    public class MobypictureApi
+    {
+        private readonly string apiKey;
+        private readonly HttpClient http;
+
+        private static readonly Uri UploadEndpoint = new Uri("https://api.mobypicture.com/2.0/upload.xml");
+
+        private static readonly Uri OAuthRealm = new Uri("http://api.twitter.com/");
+        private static readonly Uri AuthServiceProvider = new Uri("https://api.twitter.com/1.1/account/verify_credentials.json");
+
+        public MobypictureApi(TwitterApi twitterApi)
+            : this(ApplicationSettings.MobypictureKey, twitterApi)
+        {
+        }
+
+        public MobypictureApi(string apiKey, TwitterApi twitterApi)
+        {
+            this.apiKey = apiKey;
+
+            var handler = twitterApi.CreateOAuthEchoHandler(AuthServiceProvider, OAuthRealm);
+            this.http = Networking.CreateHttpClient(handler);
+            this.http.Timeout = Networking.UploadImageTimeout;
+        }
+
+        /// <summary>
+        /// 画像のアップロードを行います
+        /// </summary>
+        /// <exception cref="WebApiException"/>
+        /// <exception cref="XmlException"/>
+        public async Task<XDocument> UploadFileAsync(IMediaItem item, string message)
+        {
+            // 参照: http://developers.mobypicture.com/documentation/2-0/upload/
+
+            using var request = new HttpRequestMessage(HttpMethod.Post, UploadEndpoint);
+            using var multipart = new MultipartFormDataContent();
+            request.Content = multipart;
+
+            using var apiKeyContent = new StringContent(this.apiKey);
+            using var messageContent = new StringContent(message);
+            using var mediaStream = item.OpenRead();
+            using var mediaContent = new StreamContent(mediaStream);
+
+            multipart.Add(apiKeyContent, "key");
+            multipart.Add(messageContent, "message");
+            multipart.Add(mediaContent, "media", item.Name);
+
+            using var response = await this.http.SendAsync(request)
+                .ConfigureAwait(false);
+
+            var responseText = await response.Content.ReadAsStringAsync()
+                .ConfigureAwait(false);
+
+            if (!response.IsSuccessStatusCode)
+                throw new WebApiException(response.StatusCode.ToString(), responseText);
+
+            return XDocument.Parse(responseText);
+        }
+    }
+}
index f864743..7c2224b 100644 (file)
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
-using System.Drawing;
 using System.Data;
+using System.Diagnostics.CodeAnalysis;
+using System.Drawing;
 using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using OpenTween.Api.DataModel;
-using OpenTween.Connection;
-using System.Diagnostics.CodeAnalysis;
+using OpenTween.MediaUploadServices;
 
 namespace OpenTween
 {
@@ -29,7 +29,7 @@ using System.Text;
 using System.Threading.Tasks;
 using OpenTween.Api.DataModel;
 
-namespace OpenTween.Connection
+namespace OpenTween.MediaUploadServices
 {
     /// <summary>
     /// Twitterでの画像の共有に使用できるサービスを表すインタフェース
similarity index 72%
rename from OpenTween/Connection/Imgur.cs
rename to OpenTween/MediaUploadServices/Imgur.cs
index 38e6269..54ff9ac 100644 (file)
 
 using System;
 using System.Collections.Generic;
-using System.IO;
 using System.Linq;
-using System.Net.Http;
-using System.Net.Http.Headers;
 using System.Text;
 using System.Threading.Tasks;
-using System.Xml.Linq;
+using OpenTween.Api;
 using OpenTween.Api.DataModel;
 
-namespace OpenTween.Connection
+namespace OpenTween.MediaUploadServices
 {
     public class Imgur : IMediaUploadService
     {
@@ -139,43 +136,5 @@ namespace OpenTween.Connection
 
         public void UpdateTwitterConfiguration(TwitterConfiguration config)
             => this.twitterConfig = config;
-
-        public class ImgurApi
-        {
-            private readonly HttpClient http;
-
-            private static readonly Uri UploadEndpoint = new Uri("https://api.imgur.com/3/image.xml");
-
-            public ImgurApi()
-            {
-                this.http = Networking.CreateHttpClient(Networking.CreateHttpClientHandler());
-                this.http.Timeout = Networking.UploadImageTimeout;
-            }
-
-            public async Task<XDocument> UploadFileAsync(IMediaItem item, string title)
-            {
-                using var content = new MultipartFormDataContent();
-                using var mediaStream = item.OpenRead();
-                using var mediaContent = new StreamContent(mediaStream);
-                using var titleContent = new StringContent(title);
-
-                content.Add(mediaContent, "image", item.Name);
-                content.Add(titleContent, "title");
-
-                using var request = new HttpRequestMessage(HttpMethod.Post, UploadEndpoint);
-                request.Headers.Authorization = new AuthenticationHeaderValue("Client-ID", ApplicationSettings.ImgurClientID);
-                request.Content = content;
-
-                using var response = await this.http.SendAsync(request)
-                    .ConfigureAwait(false);
-
-                response.EnsureSuccessStatusCode();
-
-                using var stream = await response.Content.ReadAsStreamAsync()
-                    .ConfigureAwait(false);
-
-                return XDocument.Load(stream);
-            }
-        }
     }
 }
similarity index 65%
rename from OpenTween/Connection/Mobypicture.cs
rename to OpenTween/MediaUploadServices/Mobypicture.cs
index 931e233..ac983e4 100644 (file)
 
 using System;
 using System.Collections.Generic;
-using System.IO;
 using System.Linq;
-using System.Net;
-using System.Net.Http;
 using System.Text;
 using System.Threading.Tasks;
-using System.Windows.Forms;
-using System.Xml;
-using System.Xml.Linq;
-using System.Xml.XPath;
 using OpenTween.Api;
 using OpenTween.Api.DataModel;
 
-namespace OpenTween.Connection
+namespace OpenTween.MediaUploadServices
 {
     public class Mobypicture : IMediaUploadService
     {
@@ -148,57 +141,5 @@ namespace OpenTween.Connection
 
         public void UpdateTwitterConfiguration(TwitterConfiguration config)
             => this.twitterConfig = config;
-
-        public class MobypictureApi
-        {
-            private readonly HttpClient http;
-
-            private static readonly Uri UploadEndpoint = new Uri("https://api.mobypicture.com/2.0/upload.xml");
-
-            private static readonly Uri OAuthRealm = new Uri("http://api.twitter.com/");
-            private static readonly Uri AuthServiceProvider = new Uri("https://api.twitter.com/1.1/account/verify_credentials.json");
-
-            public MobypictureApi(TwitterApi twitterApi)
-            {
-                var handler = twitterApi.CreateOAuthEchoHandler(AuthServiceProvider, OAuthRealm);
-
-                this.http = Networking.CreateHttpClient(handler);
-                this.http.Timeout = Networking.UploadImageTimeout;
-            }
-
-            /// <summary>
-            /// 画像のアップロードを行います
-            /// </summary>
-            /// <exception cref="WebApiException"/>
-            /// <exception cref="XmlException"/>
-            public async Task<XDocument> UploadFileAsync(IMediaItem item, string message)
-            {
-                // 参照: http://developers.mobypicture.com/documentation/2-0/upload/
-
-                using var request = new HttpRequestMessage(HttpMethod.Post, UploadEndpoint);
-                using var multipart = new MultipartFormDataContent();
-                request.Content = multipart;
-
-                using var apiKeyContent = new StringContent(ApplicationSettings.MobypictureKey);
-                using var messageContent = new StringContent(message);
-                using var mediaStream = item.OpenRead();
-                using var mediaContent = new StreamContent(mediaStream);
-
-                multipart.Add(apiKeyContent, "key");
-                multipart.Add(messageContent, "message");
-                multipart.Add(mediaContent, "media", item.Name);
-
-                using var response = await this.http.SendAsync(request)
-                    .ConfigureAwait(false);
-
-                var responseText = await response.Content.ReadAsStringAsync()
-                    .ConfigureAwait(false);
-
-                if (!response.IsSuccessStatusCode)
-                    throw new WebApiException(response.StatusCode.ToString(), responseText);
-
-                return XDocument.Parse(responseText);
-            }
-        }
     }
 }
similarity index 99%
rename from OpenTween/Connection/TwitterPhoto.cs
rename to OpenTween/MediaUploadServices/TwitterPhoto.cs
index ee1350b..5356f7b 100644 (file)
@@ -37,7 +37,7 @@ using System.Threading.Tasks;
 using OpenTween.Api.DataModel;
 using OpenTween.Setting;
 
-namespace OpenTween.Connection
+namespace OpenTween.MediaUploadServices
 {
     public class TwitterPhoto : IMediaUploadService
     {
index e0203c0..94bfe47 100644 (file)
     <Compile Include="Api\DataModel\TwitterUploadMediaResult.cs" />
     <Compile Include="Api\DataModel\TwitterUser.cs" />
     <Compile Include="Api\DataModel\TwitterApiAccessLevel.cs" />
+    <Compile Include="Api\ImgurApi.cs" />
     <Compile Include="Api\JsonUtils.cs" />
     <Compile Include="Api\MicrosoftTranslatorApi.cs" />
+    <Compile Include="Api\MobypictureApi.cs" />
     <Compile Include="Api\TwitterApi.cs" />
     <Compile Include="Api\TwitterApiException.cs" />
     <Compile Include="Api\TwitterApiStatus.cs" />
     </Compile>
     <Compile Include="Bing.cs" />
     <Compile Include="Connection\IApiConnection.cs" />
-    <Compile Include="Connection\IMediaUploadService.cs" />
-    <Compile Include="Connection\Imgur.cs" />
+    <Compile Include="MediaUploadServices\IMediaUploadService.cs" />
+    <Compile Include="MediaUploadServices\Imgur.cs" />
     <Compile Include="Connection\LazyJson.cs" />
-    <Compile Include="Connection\Mobypicture.cs" />
+    <Compile Include="MediaUploadServices\Mobypicture.cs" />
     <Compile Include="Connection\Networking.cs" />
     <Compile Include="Connection\OAuthEchoHandler.cs" />
     <Compile Include="Connection\OAuthHandler.cs" />
     <Compile Include="ListManage.Designer.cs">
       <DependentUpon>ListManage.cs</DependentUpon>
     </Compile>
-    <Compile Include="Connection\TwitterPhoto.cs" />
+    <Compile Include="MediaUploadServices\TwitterPhoto.cs" />
     <Compile Include="DetailsListView.cs">
       <SubType>Component</SubType>
     </Compile>
index 6171cc8..51289fe 100644 (file)
@@ -53,6 +53,7 @@ using System.Windows.Forms;
 using OpenTween.Api;
 using OpenTween.Api.DataModel;
 using OpenTween.Connection;
+using OpenTween.MediaUploadServices;
 using OpenTween.Models;
 using OpenTween.OpenTweenCustomControl;
 using OpenTween.Setting;