--- /dev/null
+// 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);
+ }
+ }
+}
--- /dev/null
+// 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);
+ }
+ }
+}
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
{
using System.Threading.Tasks;
using OpenTween.Api.DataModel;
-namespace OpenTween.Connection
+namespace OpenTween.MediaUploadServices
{
/// <summary>
/// Twitterでの画像の共有に使用できるサービスを表すインタフェース
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
{
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);
- }
- }
}
}
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
{
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);
- }
- }
}
}
using OpenTween.Api.DataModel;
using OpenTween.Setting;
-namespace OpenTween.Connection
+namespace OpenTween.MediaUploadServices
{
public class TwitterPhoto : IMediaUploadService
{
<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>
using OpenTween.Api;
using OpenTween.Api.DataModel;
using OpenTween.Connection;
+using OpenTween.MediaUploadServices;
using OpenTween.Models;
using OpenTween.OpenTweenCustomControl;
using OpenTween.Setting;