OSDN Git Service

使用されていないフィールドを削除 (CA1823)
[opentween/open-tween.git] / OpenTween / Connection / HttpTwitter.cs
index fb5816c..1639fc4 100644 (file)
@@ -20,7 +20,7 @@
 // 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
+// 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.
 
@@ -44,13 +44,10 @@ namespace OpenTween
         private const string AuthorizeUrl = "https://api.twitter.com/oauth/authorize";
         private const string AccessTokenUrl = "https://api.twitter.com/oauth/access_token";
 
-        private static string _protocol = "http://";
-
         private const string PostMethod = "POST";
         private const string GetMethod = "GET";
 
         private IHttpConnection httpCon; //HttpConnectionApi or HttpConnectionOAuth
-        private HttpVarious httpConVar = new HttpVarious();
 
         private enum AuthMethod
         {
@@ -166,18 +163,7 @@ namespace OpenTween
             this.Initialize("", "", "", 0);
         }
 
-        public static bool UseSsl
-        {
-            set
-            {
-                if (value)
-                    _protocol = "https://";
-                else
-                    _protocol = "http://";
-            }
-        }
-
-        public HttpStatusCode UpdateStatus(string status, long? replyToId, ref string content)
+        public HttpStatusCode UpdateStatus(string status, long? replyToId, List<long> mediaIds, ref string content)
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
             param.Add("status", status);
@@ -185,6 +171,9 @@ namespace OpenTween
             param.Add("include_entities", "true");
             //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
 
+            if (mediaIds != null && mediaIds.Count > 0)
+                param.Add("media_ids", string.Join(",", mediaIds));
+
             return httpCon.GetContent(PostMethod,
                 this.CreateTwitterUri("/1.1/statuses/update.json"),
                 param,
@@ -210,10 +199,25 @@ namespace OpenTween
                 param,
                 binary,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/statuses/update_with_media"));
         }
 
+        public HttpStatusCode UploadMedia(FileInfo mediaFile, ref string content)
+        {
+            //画像投稿専用エンドポイント
+            List<KeyValuePair<string, FileInfo>> binary = new List<KeyValuePair<string, FileInfo>>();
+            binary.Add(new KeyValuePair<string, FileInfo>("media", mediaFile));
+
+            return httpCon.GetContent(PostMethod,
+                this.CreateTwitterUploadUri("/1.1/media/upload.json"),
+                null,
+                binary,
+                ref content,
+                null,
+                null);
+        }
+
         public HttpStatusCode DestroyStatus(long id)
         {
             string content = null;
@@ -278,7 +282,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/users/show.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/users/show/:id"));
         }
 
@@ -357,7 +361,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/friendships/show.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/friendships/show"));
         }
 
@@ -369,7 +373,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/statuses/show/" + id + ".json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/statuses/show/:id"));
         }
 
@@ -415,7 +419,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/statuses/home_timeline.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/statuses/home_timeline"));
         }
 
@@ -444,7 +448,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/statuses/user_timeline.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/statuses/user_timeline"));
         }
 
@@ -464,7 +468,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/statuses/mentions_timeline.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/statuses/mentions_timeline"));
         }
 
@@ -483,7 +487,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/direct_messages.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/direct_messages"));
         }
 
@@ -502,7 +506,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/direct_messages/sent.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/direct_messages/sent"));
         }
 
@@ -522,7 +526,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/favorites/list.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/favorites/list"));
         }
 
@@ -543,7 +547,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/search/tweets.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/search/tweets"));
         }
 
@@ -553,7 +557,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/saved_searches/list.json"),
                 null,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/saved_searches/list"));
         }
 
@@ -566,7 +570,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/followers/ids.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/followers/ids"));
         }
 
@@ -576,7 +580,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/friendships/no_retweets/ids.json"),
                 null,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/friendships/no_retweets/ids"));
         }
 
@@ -586,7 +590,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/application/rate_limit_status.json"),
                 null,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/application/rate_limit_status"));
         }
 
@@ -600,7 +604,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/lists/list.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/lists/list"));
         }
 
@@ -648,7 +652,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/lists/subscriptions.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/lists/subscriptions"));
         }
 
@@ -671,7 +675,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/lists/statuses.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/lists/statuses"));
         }
 
@@ -705,7 +709,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/lists/members.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/lists/members"));
         }
 
@@ -744,7 +748,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/lists/members/show.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/lists/members/show"));
         }
         #endregion
@@ -763,7 +767,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/statuses/retweeters/ids.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/statuses/retweeters/ids"));
         }
 
@@ -810,17 +814,32 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/blocks/ids.json"),
                 param,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/blocks/ids"));
         }
 
+        public HttpStatusCode GetMuteUserIds(ref string content, long? cursor)
+        {
+            var param = new Dictionary<string, string>();
+
+            if (cursor != null)
+                param.Add("cursor", cursor.ToString());
+
+            return httpCon.GetContent(GetMethod,
+                this.CreateTwitterUri("/1.1/mutes/users/ids.json"),
+                param,
+                ref content,
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/1.1/mutes/users/ids"));
+        }
+
         public HttpStatusCode GetConfiguration(ref string content)
         {
             return httpCon.GetContent(GetMethod,
                 this.CreateTwitterUri("/1.1/help/configuration.json"),
                 null,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/help/configuration"));
         }
 
@@ -830,7 +849,7 @@ namespace OpenTween
                 this.CreateTwitterUri("/1.1/account/verify_credentials.json"),
                 null,
                 ref content,
-                this.CreateRetelimitHeadersDict(),
+                this.CreateRatelimitHeadersDict(),
                 this.CreateApiCalllback("/account/verify_credentials"));
         }
 
@@ -838,10 +857,11 @@ namespace OpenTween
         private static string _twitterUrl = "api.twitter.com";
         private static string _twitterUserStreamUrl = "userstream.twitter.com";
         private static string _twitterStreamUrl = "stream.twitter.com";
+        private static string _twitterUploadUrl = "upload.twitter.com";
 
         private Uri CreateTwitterUri(string path)
         {
-            return new Uri(string.Format("{0}{1}{2}", _protocol, _twitterUrl, path));
+            return new Uri(string.Format("{0}{1}{2}", "https://", _twitterUrl, path));
         }
 
         private Uri CreateTwitterUserStreamUri(string path)
@@ -854,6 +874,11 @@ namespace OpenTween
             return new Uri(string.Format("{0}{1}{2}", "http://", _twitterStreamUrl, path));
         }
 
+        private Uri CreateTwitterUploadUri(string path)
+        {
+            return new Uri(string.Format("{0}{1}{2}", "https://", _twitterUploadUrl, path));
+        }
+
         public static string TwitterUrl
         {
             set
@@ -864,7 +889,7 @@ namespace OpenTween
         }
         #endregion
 
-        private Dictionary<string, string> CreateRetelimitHeadersDict()
+        private Dictionary<string, string> CreateRatelimitHeadersDict()
         {
             return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
             {