OSDN Git Service

使用されていないフィールドを削除 (CA1823)
[opentween/open-tween.git] / OpenTween / Connection / HttpTwitter.cs
index 25591c1..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.
 
@@ -35,15 +35,6 @@ namespace OpenTween
 {
     public class HttpTwitter : ICloneable
     {
-        /// <summary>
-        /// API v1.1 を有効にする否か
-        /// </summary>
-        /// <remarks>
-        /// 旧APIが使用出来なくなったら消す予定。
-        /// 静的フィールドとしているのは TwitterUserstream クラスが Clone メソッドを使用しているため
-        /// </remarks>
-        public static bool API11Enabled { get; set; }
-
         //OAuth関連
         ///<summary>
         ///OAuthのアクセストークン取得先URI
@@ -53,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
         {
@@ -74,25 +62,6 @@ namespace OpenTween
         private static string tks = "";
         private static string un = "";
 
-        private Dictionary<string, string> apiStatusHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
-        {
-            {"X-Access-Level", ""},
-            {"X-RateLimit-Limit", ""},
-            {"X-RateLimit-Remaining", ""},
-            {"X-RateLimit-Reset", ""},
-            {"X-Rate-Limit-Limit", ""},
-            {"X-Rate-Limit-Remaining", ""},
-            {"X-Rate-Limit-Reset", ""},
-            {"X-MediaRateLimit-Limit", ""},
-            {"X-MediaRateLimit-Remaining", ""},
-            {"X-MediaRateLimit-Reset", ""},
-        };
-
-        static HttpTwitter()
-        {
-            HttpTwitter.API11Enabled = true;
-        }
-
         public void Initialize(string accessToken,
                                         string accessTokenSecret,
                                         string username,
@@ -194,39 +163,31 @@ 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);
-            if (replyToId > 0) param.Add("in_reply_to_status_id", replyToId.ToString());
+            if (replyToId != null) param.Add("in_reply_to_status_id", replyToId.ToString());
             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,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/update.json" : "/1/statuses/update.json"),
+                this.CreateTwitterUri("/1.1/statuses/update.json"),
                 param,
                 ref content,
                 null,
                 null);
         }
 
-        public HttpStatusCode UpdateStatusWithMedia(string status, long replyToId, FileInfo mediaFile, ref string content)
+        public HttpStatusCode UpdateStatusWithMedia(string status, long? replyToId, FileInfo mediaFile, ref string content)
         {
             //画像投稿用エンドポイント
             Dictionary<string, string> param = new Dictionary<string, string>();
             param.Add("status", status);
-            if (replyToId > 0) param.Add("in_reply_to_status_id", replyToId.ToString());
+            if (replyToId != null) param.Add("in_reply_to_status_id", replyToId.ToString());
             param.Add("include_entities", "true");
             //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
 
@@ -234,25 +195,36 @@ namespace OpenTween
             binary.Add(new KeyValuePair<string, FileInfo>("media[]", mediaFile));
 
             return httpCon.GetContent(PostMethod,
-                HttpTwitter.API11Enabled ? CreateTwitterUri("/1.1/statuses/update_with_media.json") : new Uri("https://upload.twitter.com/1/statuses/update_with_media.json"),
+                this.CreateTwitterUri("/1.1/statuses/update_with_media.json"),
                 param,
                 binary,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/update_with_media") : GetApiCallback);
+                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;
 
-            var param = new Dictionary<string, string>();
-            if (HttpTwitter.API11Enabled)
-                param.Add("id", id.ToString());
-
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/destroy.json" : "/1/statuses/destroy/" + id + ".json"),
-                param,
+                this.CreateTwitterUri("/1.1/statuses/destroy/" + id + ".json"),
+                null,
                 ref content,
                 null,
                 null);
@@ -266,7 +238,7 @@ namespace OpenTween
             //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/direct_messages/new.json" : "/1/direct_messages/new.json"),
+                this.CreateTwitterUri("/1.1/direct_messages/new.json"),
                 param,
                 ref content,
                 null,
@@ -278,11 +250,10 @@ namespace OpenTween
             string content = null;
 
             var param = new Dictionary<string, string>();
-            if (HttpTwitter.API11Enabled)
-                param.Add("id", id.ToString());
+            param.Add("id", id.ToString());
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/direct_messages/destroy.json" : "/1/direct_messages/destroy/" + id + ".json"),
+                this.CreateTwitterUri("/1.1/direct_messages/destroy.json"),
                 param,
                 ref content,
                 null,
@@ -295,7 +266,7 @@ namespace OpenTween
             param.Add("include_entities", "true");
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/retweet/" + id + ".json" : "/1/statuses/retweet/" + id + ".json"),
+                this.CreateTwitterUri("/1.1/statuses/retweet/" + id + ".json"),
                 param,
                 ref content,
                 null,
@@ -308,11 +279,11 @@ namespace OpenTween
             param.Add("screen_name", screenName);
             param.Add("include_entities", "true");
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/users/show.json" : "/1/users/show.json"),
+                this.CreateTwitterUri("/1.1/users/show.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/users/show/:id") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/users/show/:id"));
         }
 
         public HttpStatusCode CreateFriendships(string screenName, ref string content)
@@ -321,7 +292,7 @@ namespace OpenTween
             param.Add("screen_name", screenName);
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/friendships/create.json" : "/1/friendships/create.json"),
+                this.CreateTwitterUri("/1.1/friendships/create.json"),
                 param,
                 ref content,
                 null,
@@ -334,7 +305,7 @@ namespace OpenTween
             param.Add("screen_name", screenName);
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/friendships/destroy.json" : "/1/friendships/destroy.json"),
+                this.CreateTwitterUri("/1.1/friendships/destroy.json"),
                 param,
                 ref content,
                 null,
@@ -347,7 +318,7 @@ namespace OpenTween
             param.Add("screen_name", screenName);
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/blocks/create.json" : "/1/blocks/create.json"),
+                this.CreateTwitterUri("/1.1/blocks/create.json"),
                 param,
                 ref content,
                 null,
@@ -360,7 +331,7 @@ namespace OpenTween
             param.Add("screen_name", screenName);
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/blocks/destroy.json" : "/1/blocks/destroy.json"),
+                this.CreateTwitterUri("/1.1/blocks/destroy.json"),
                 param,
                 ref content,
                 null,
@@ -373,7 +344,7 @@ namespace OpenTween
             param.Add("screen_name", screenName);
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/users/report_spam.json" : "/1/report_spam.json"),
+                this.CreateTwitterUri("/1.1/users/report_spam.json"),
                 param,
                 ref content,
                 null,
@@ -387,11 +358,11 @@ namespace OpenTween
             param.Add("target_screen_name", targetScreenName);
 
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/friendships/show.json" : "/1/friendships/show.json"),
+                this.CreateTwitterUri("/1.1/friendships/show.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/friendships/show") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/friendships/show"));
         }
 
         public HttpStatusCode ShowStatuses(long id, ref string content)
@@ -399,21 +370,20 @@ namespace OpenTween
             Dictionary<string, string> param = new Dictionary<string, string>();
             param.Add("include_entities", "true");
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/show/" + id + ".json" : "/1/statuses/show/" + id + ".json"),
+                this.CreateTwitterUri("/1.1/statuses/show/" + id + ".json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/show/:id") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/statuses/show/:id"));
         }
 
         public HttpStatusCode CreateFavorites(long id, ref string content)
         {
             var param = new Dictionary<string, string>();
-            if (HttpTwitter.API11Enabled)
-                param.Add("id", id.ToString());
+            param.Add("id", id.ToString());
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/favorites/create.json" : "/1/favorites/create/" + id + ".json"),
+                this.CreateTwitterUri("/1.1/favorites/create.json"),
                 param,
                 ref content,
                 null,
@@ -423,152 +393,129 @@ namespace OpenTween
         public HttpStatusCode DestroyFavorites(long id, ref string content)
         {
             var param = new Dictionary<string, string>();
-            if (HttpTwitter.API11Enabled)
-                param.Add("id", id.ToString());
+            param.Add("id", id.ToString());
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/favorites/destroy.json" : "/1/favorites/destroy/" + id + ".json"),
-                null,
+                this.CreateTwitterUri("/1.1/favorites/destroy.json"),
+                param,
                 ref content,
                 null,
                 null);
         }
 
-        public HttpStatusCode HomeTimeline(int count, long max_id, long since_id, ref string content)
+        public HttpStatusCode HomeTimeline(int? count, long? max_id, long? since_id, ref string content)
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
-            if (count > 0)
+            if (count != null)
                 param.Add("count", count.ToString());
-            if (max_id > 0)
+            if (max_id != null)
                 param.Add("max_id", max_id.ToString());
-            if (since_id > 0)
+            if (since_id != null)
                 param.Add("since_id", since_id.ToString());
 
             param.Add("include_entities", "true");
 
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/home_timeline.json" : "/1/statuses/home_timeline.json"),
+                this.CreateTwitterUri("/1.1/statuses/home_timeline.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/home_timeline") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/statuses/home_timeline"));
         }
 
-        public HttpStatusCode UserTimeline(long user_id, string screen_name, int count, long max_id, long since_id, ref string content)
+        public HttpStatusCode UserTimeline(long? user_id, string screen_name, int? count, long? max_id, long? since_id, ref string content)
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
 
-            if ((user_id == 0 && string.IsNullOrEmpty(screen_name)) ||
-                (user_id != 0 && !string.IsNullOrEmpty(screen_name))) return HttpStatusCode.BadRequest;
+            if ((user_id == null && string.IsNullOrEmpty(screen_name)) ||
+                (user_id != null && !string.IsNullOrEmpty(screen_name))) return HttpStatusCode.BadRequest;
 
-            if (user_id > 0)
+            if (user_id != null)
                 param.Add("user_id", user_id.ToString());
             if (!string.IsNullOrEmpty(screen_name))
                 param.Add("screen_name", screen_name);
-            if (count > 0)
+            if (count != null)
                 param.Add("count", count.ToString());
-            if (max_id > 0)
+            if (max_id != null)
                 param.Add("max_id", max_id.ToString());
-            if (since_id > 0)
+            if (since_id != null)
                 param.Add("since_id", since_id.ToString());
 
             param.Add("include_rts", "true");
             param.Add("include_entities", "true");
 
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/user_timeline.json" : "/1/statuses/user_timeline.json"),
+                this.CreateTwitterUri("/1.1/statuses/user_timeline.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/user_timeline") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/statuses/user_timeline"));
         }
 
-        public HttpStatusCode PublicTimeline(int count, long max_id, long since_id, ref string content)
+        public HttpStatusCode Mentions(int? count, long? max_id, long? since_id, ref string content)
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
-            if (count > 0)
+            if (count != null)
                 param.Add("count", count.ToString());
-            if (max_id > 0)
+            if (max_id != null)
                 param.Add("max_id", max_id.ToString());
-            if (since_id > 0)
+            if (since_id != null)
                 param.Add("since_id", since_id.ToString());
 
             param.Add("include_entities", "true");
 
-            // TODO: API v1.1 に存在しない API (旧 API で代替)
-
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri("/1/statuses/public_timeline.json"),
+                this.CreateTwitterUri("/1.1/statuses/mentions_timeline.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/statuses/mentions_timeline"));
         }
 
-        public HttpStatusCode Mentions(int count, long max_id, long since_id, ref string content)
+        public HttpStatusCode DirectMessages(int? count, long? max_id, long? since_id, ref string content)
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
-            if (count > 0)
+            if (count != null)
                 param.Add("count", count.ToString());
-            if (max_id > 0)
+            if (max_id != null)
                 param.Add("max_id", max_id.ToString());
-            if (since_id > 0)
+            if (since_id != null)
                 param.Add("since_id", since_id.ToString());
-
             param.Add("include_entities", "true");
 
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/mentions_timeline.json" : "/1/statuses/mentions.json"),
+                this.CreateTwitterUri("/1.1/direct_messages.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/mentions_timeline") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/direct_messages"));
         }
 
-        public HttpStatusCode DirectMessages(int count, long max_id, long since_id, ref string content)
+        public HttpStatusCode DirectMessagesSent(int? count, long? max_id, long? since_id, ref string content)
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
-            if (count > 0)
+            if (count != null)
                 param.Add("count", count.ToString());
-            if (max_id > 0)
+            if (max_id != null)
                 param.Add("max_id", max_id.ToString());
-            if (since_id > 0)
+            if (since_id != null)
                 param.Add("since_id", since_id.ToString());
             param.Add("include_entities", "true");
 
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/direct_messages.json" : "/1/direct_messages.json"),
+                this.CreateTwitterUri("/1.1/direct_messages/sent.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/direct_messages") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/direct_messages/sent"));
         }
 
-        public HttpStatusCode DirectMessagesSent(int count, long max_id, long since_id, ref string content)
+        public HttpStatusCode Favorites(int? count, int? page, ref string content)
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
-            if (count > 0)
-                param.Add("count", count.ToString());
-            if (max_id > 0)
-                param.Add("max_id", max_id.ToString());
-            if (since_id > 0)
-                param.Add("since_id", since_id.ToString());
-            param.Add("include_entities", "true");
+            if (count != null) param.Add("count", count.ToString());
 
-            return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/direct_messages/sent.json" : "/1/direct_messages/sent.json"),
-                param,
-                ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/direct_messages/sent") : GetApiCallback);
-        }
-
-        public HttpStatusCode Favorites(int count, int page, ref string content)
-        {
-            Dictionary<string, string> param = new Dictionary<string, string>();
-            if (count != 20) param.Add("count", count.ToString());
-
-            if (page > 0)
+            if (page != null)
             {
                 param.Add("page", page.ToString());
             }
@@ -576,85 +523,42 @@ namespace OpenTween
             param.Add("include_entities", "true");
 
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/favorites/list.json" : "/1/favorites.json"),
+                this.CreateTwitterUri("/1.1/favorites/list.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/favorites/list") : GetApiCallback);
-        }
-
-        public HttpStatusCode PhoenixSearch(string querystr, ref string content)
-        {
-            Dictionary<string, string> param = new Dictionary<string, string>();
-            string[] tmp;
-            string[] paramstr;
-            if (string.IsNullOrEmpty(querystr)) return HttpStatusCode.BadRequest;
-
-            tmp = querystr.Split(new char[] {'?', '&'}, StringSplitOptions.RemoveEmptyEntries);
-            foreach (string tmp2 in tmp)
-            {
-                paramstr = tmp2.Split(new char[] {'='});
-                param.Add(paramstr[0], paramstr[1]);
-            }
-
-            return httpConVar.GetContent(GetMethod,
-                                         CreateTwitterUri("/phoenix_search.phoenix"),
-                                         param,
-                                         out content,
-                                         null,
-                                         MyCommon.GetAssemblyName());
-        }
-
-        public HttpStatusCode PhoenixSearch(string words, string lang, int rpp, int page, long sinceId, ref string content)
-        {
-            Dictionary<string, string> param = new Dictionary<string, string>();
-            if (!string.IsNullOrEmpty(words)) param.Add("q", words);
-            param.Add("include_entities", "1");
-            param.Add("contributor_details", "true");
-            if (!string.IsNullOrEmpty(lang)) param.Add("lang", lang);
-            if (rpp > 0) param.Add("rpp", rpp.ToString());
-            if (page > 0) param.Add("page", page.ToString());
-            if (sinceId > 0) param.Add("since_id", sinceId.ToString());
-
-            if (param.Count == 0) return HttpStatusCode.BadRequest;
-
-            return httpConVar.GetContent(GetMethod,
-                                         CreateTwitterUri("/phoenix_search.phoenix"),
-                                         param,
-                                         out content,
-                                         null,
-                                         MyCommon.GetAssemblyName());
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/favorites/list"));
         }
 
-        public HttpStatusCode Search(string words, string lang, int count, int page, long sinceId, ref string content)
+        public HttpStatusCode Search(string words, string lang, int? count, long? maxId, long? sinceId, ref string content)
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
             if (!string.IsNullOrEmpty(words)) param.Add("q", words);
             if (!string.IsNullOrEmpty(lang)) param.Add("lang", lang);
-            if (count > 0) param.Add(HttpTwitter.API11Enabled ? "count" : "rpp", count.ToString());
-            if (page > 0) param.Add("page", page.ToString());
-            if (sinceId > 0) param.Add("since_id", sinceId.ToString());
+            if (count != null) param.Add("count", count.ToString());
+            if (maxId != null) param.Add("max_id", maxId.ToString());
+            if (sinceId != null) param.Add("since_id", sinceId.ToString());
 
             if (param.Count == 0) return HttpStatusCode.BadRequest;
 
             param.Add("result_type", "recent");
             param.Add("include_entities", "true");
             return httpCon.GetContent(GetMethod,
-                HttpTwitter.API11Enabled ? this.CreateTwitterUri("/1.1/search/tweets.json") : this.CreateTwitterSearchUri("/search.json"),
+                this.CreateTwitterUri("/1.1/search/tweets.json"),
                 param,
                 ref content,
-                null,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/search/tweets") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/search/tweets"));
         }
 
         public HttpStatusCode SavedSearches(ref string content)
         {
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/saved_searches/list.json" : "/1/saved_searches.json"),
+                this.CreateTwitterUri("/1.1/saved_searches/list.json"),
                 null,
                 ref content,
-                null,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/saved_searches/list") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/saved_searches/list"));
         }
 
         public HttpStatusCode FollowerIds(long cursor, ref string content)
@@ -663,48 +567,45 @@ namespace OpenTween
             param.Add("cursor", cursor.ToString());
 
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/followers/ids.json" : "/1/followers/ids.json"),
+                this.CreateTwitterUri("/1.1/followers/ids.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/followers/ids") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/followers/ids"));
         }
 
-        public HttpStatusCode NoRetweetIds(long cursor, ref string content)
+        public HttpStatusCode NoRetweetIds(ref string content)
         {
-            Dictionary<string, string> param = new Dictionary<string, string>();
-            param.Add("cursor", cursor.ToString());
-
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/friendships/no_retweets/ids.json" : "/1/friendships/no_retweet_ids.json"),
-                param,
+                this.CreateTwitterUri("/1.1/friendships/no_retweets/ids.json"),
+                null,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/friendships/no_retweets/ids") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/friendships/no_retweets/ids"));
         }
 
         public HttpStatusCode RateLimitStatus(ref string content)
         {
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/application/rate_limit_status.json" : "/1/account/rate_limit_status.json"),
+                this.CreateTwitterUri("/1.1/application/rate_limit_status.json"),
                 null,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/application/rate_limit_status") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/application/rate_limit_status"));
         }
 
         #region Lists
-        public HttpStatusCode GetLists(string user, long cursor, ref string content)
+        public HttpStatusCode GetLists(string user, ref string content)
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
             param.Add("screen_name", user);
-            param.Add("cursor", cursor.ToString());
+
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/list.json" : "/1/lists.json"),
+                this.CreateTwitterUri("/1.1/lists/list.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/list") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/lists/list"));
         }
 
         public HttpStatusCode UpdateListID(string user, string list_id, string name, Boolean isPrivate, string description, ref string content)
@@ -721,7 +622,7 @@ namespace OpenTween
             if (description != null) param.Add("description", description);
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/update.json" : "/1/lists/update.json"),
+                this.CreateTwitterUri("/1.1/lists/update.json"),
                 param,
                 ref content,
                 null,
@@ -735,47 +636,47 @@ namespace OpenTween
             param.Add("list_id", list_id);
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/destroy.json" : "/1/lists/destroy.json"),
+                this.CreateTwitterUri("/1.1/lists/destroy.json"),
                 param,
                 ref content,
                 null,
                 null);
         }
 
-        public HttpStatusCode GetListsSubscriptions(string user, long cursor, ref string content)
+        public HttpStatusCode GetListsSubscriptions(string user, ref string content)
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
             param.Add("screen_name", user);
-            param.Add("cursor", cursor.ToString());
+
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/subscriptions.json" : "/1/lists/subscriptions.json"),
+                this.CreateTwitterUri("/1.1/lists/subscriptions.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/subscriptions") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/lists/subscriptions"));
         }
 
-        public HttpStatusCode GetListsStatuses(long userId, long list_id, int per_page, long max_id, long since_id, Boolean isRTinclude, ref string content)
+        public HttpStatusCode GetListsStatuses(long userId, long list_id, int? per_page, long? max_id, long? since_id, Boolean isRTinclude, ref string content)
         {
             //認証なくても取得できるが、protectedユーザー分が抜ける
             Dictionary<string, string> param = new Dictionary<string, string>();
             param.Add("user_id", userId.ToString());
             param.Add("list_id", list_id.ToString());
             param.Add("include_rts", isRTinclude ? "true" : "false");
-            if (per_page > 0)
-                param.Add("per_page", per_page.ToString());
-            if (max_id > 0)
+            if (per_page != null)
+                param.Add("count", per_page.ToString());
+            if (max_id != null)
                 param.Add("max_id", max_id.ToString());
-            if (since_id > 0)
+            if (since_id != null)
                 param.Add("since_id", since_id.ToString());
             param.Add("include_entities", "true");
 
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/statuses.json" : "/1/lists/statuses.json"),
+                this.CreateTwitterUri("/1.1/lists/statuses.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/statuses") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/lists/statuses"));
         }
 
         public HttpStatusCode CreateLists(string listname, Boolean isPrivate, string description, ref string content)
@@ -791,7 +692,7 @@ namespace OpenTween
                 param.Add("description", description);
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/create.json" : "/1/lists/create.json"),
+                this.CreateTwitterUri("/1.1/lists/create.json"),
                 param,
                 ref content,
                 null,
@@ -805,11 +706,11 @@ namespace OpenTween
             param.Add("list_id", list_id);
             param.Add("cursor", cursor.ToString());
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/members.json" : "/1/lists/members.json"),
+                this.CreateTwitterUri("/1.1/lists/members.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/members") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/lists/members"));
         }
 
         public HttpStatusCode CreateListMembers(string list_id, string memberName, ref string content)
@@ -818,104 +719,56 @@ namespace OpenTween
             param.Add("list_id", list_id);
             param.Add("screen_name", memberName);
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/members/create.json" : "/1/lists/members/create.json"),
+                this.CreateTwitterUri("/1.1/lists/members/create.json"),
                 param,
                 ref content,
                 null,
                 null);
         }
 
-        //public HttpStatusCode CreateListMembers(string user, string list_id, string memberName, ref string content)
-        //{
-        //    //正常に動かないので旧APIで様子見
-        //    //Dictionary<string, string> param = new Dictionary<string, string>();
-        //    //param.Add("screen_name", user)
-        //    //param.Add("list_id", list_id)
-        //    //param.Add("member_screen_name", memberName)
-        //    //return httpCon.GetContent(PostMethod,
-        //    //                          CreateTwitterUri("/1/lists/members/create.json"),
-        //    //                          param,
-        //    //                          ref content,
-        //    //                          null,
-        //    //                          null)
-        //    Dictionary<string, string> param = new Dictionary<string, string>();
-        //    param.Add("id", memberName)
-        //    return httpCon.GetContent(PostMethod,
-        //                              CreateTwitterUri("/1/" + user + "/" + list_id + "/members.json"),
-        //                              param,
-        //                              ref content,
-        //                              null,
-        //                              null)
-        //}
-
         public HttpStatusCode DeleteListMembers(string list_id, string memberName, ref string content)
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
             param.Add("screen_name", memberName);
             param.Add("list_id", list_id);
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/members/destroy.json" : "/1/lists/members/destroy.json"),
+                this.CreateTwitterUri("/1.1/lists/members/destroy.json"),
                 param,
                 ref content,
                 null,
                 null);
         }
 
-        //public HttpStatusCode DeleteListMembers(string user, string list_id, string memberName, ref string content)
-        //{
-        //    //Dictionary<string, string> param = new Dictionary<string, string>();
-        //    //param.Add("screen_name", user)
-        //    //param.Add("list_id", list_id)
-        //    //param.Add("member_screen_name", memberName)
-        //    //return httpCon.GetContent(PostMethod,
-        //    //                          CreateTwitterUri("/1/lists/members/destroy.json"),
-        //    //                          param,
-        //    //                          ref content,
-        //    //                          null,
-        //    //                          null)
-        //    Dictionary<string, string> param = new Dictionary<string, string>();
-        //    param.Add("id", memberName)
-        //    param.Add("_method", "DELETE")
-        //    return httpCon.GetContent(PostMethod,
-        //                              CreateTwitterUri("/1/" + user + "/" + list_id + "/members.json"),
-        //                              param,
-        //                              ref content,
-        //                              null,
-        //                              null)
-        //}
-
         public HttpStatusCode ShowListMember(string list_id, string memberName, ref string content)
         {
-            //新APIがmember_screen_nameもmember_user_idも無視して、自分のIDを返してくる。
-            //正式にドキュメントに反映されるまで旧APIを使用する
             Dictionary<string, string> param = new Dictionary<string, string>();
             param.Add("screen_name", memberName);
             param.Add("list_id", list_id);
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/members/show.json" : "/1/lists/members/show.json"),
+                this.CreateTwitterUri("/1.1/lists/members/show.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/members/show") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/lists/members/show"));
         }
         #endregion
 
-        public HttpStatusCode Statusid_retweeted_by_ids(long statusid, int count, int page, ref string content)
+        public HttpStatusCode Statusid_retweeted_by_ids(long statusid, int? count, int? page, ref string content)
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
-            if (count > 0)
+            if (count != null)
                 param.Add("count", count.ToString());
-            if (page > 0)
+            if (page != null)
                 param.Add("page", page.ToString());
 
-            // TODO: API v1.1 に存在しない API (旧 API で代替)
+            param.Add("id", statusid.ToString());
 
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri("/1/statuses/" + statusid + "/retweeted_by/ids.json"),
+                this.CreateTwitterUri("/1.1/statuses/retweeters/ids.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/statuses/retweeters/ids"));
         }
 
         public HttpStatusCode UpdateProfile(string name, string url, string location, string description, ref string content)
@@ -929,7 +782,7 @@ namespace OpenTween
             param.Add("include_entities", "true");
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/account/update_profile.json" : "/1/account/update_profile.json"),
+                this.CreateTwitterUri("/1.1/account/update_profile.json"),
                 param,
                 ref content,
                 null,
@@ -942,7 +795,7 @@ namespace OpenTween
             binary.Add(new KeyValuePair<string, FileInfo>("image", imageFile));
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/account/update_profile_image.json" : "/1/account/update_profile_image.json"),
+                this.CreateTwitterUri("/1.1/account/update_profile_image.json"),
                 null,
                 binary,
                 ref content,
@@ -950,67 +803,65 @@ namespace OpenTween
                 null);
         }
 
-        public HttpStatusCode GetRelatedResults(long id, ref string content)
+        public HttpStatusCode GetBlockUserIds(ref string content, long? cursor)
         {
-            //認証なくても取得できるが、protectedユーザー分が抜ける
-            Dictionary<string, string> param = new Dictionary<string, string>();
-
-            param.Add("include_entities", "true");
+            var param = new Dictionary<string, string>();
 
-            // TODO: API v1.1 に存在しない API (旧 API で代替)
+            if (cursor != null)
+                param.Add("cursor", cursor.ToString());
 
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri("/1/related_results/show/" + id + ".json"),
+                this.CreateTwitterUri("/1.1/blocks/ids.json"),
                 param,
                 ref content,
-                this.apiStatusHeaders,
-                GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/blocks/ids"));
         }
 
-        public HttpStatusCode GetBlockUserIds(ref string content)
+        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,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/blocks/ids.json" : "/1/blocks/blocking/ids.json"),
-                null,
+                this.CreateTwitterUri("/1.1/mutes/users/ids.json"),
+                param,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/blocks/ids") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/1.1/mutes/users/ids"));
         }
 
         public HttpStatusCode GetConfiguration(ref string content)
         {
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/help/configuration.json" : "/1/help/configuration.json"),
+                this.CreateTwitterUri("/1.1/help/configuration.json"),
                 null,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/help/configuration") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/help/configuration"));
         }
 
         public HttpStatusCode VerifyCredentials(ref string content)
         {
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/account/verify_credentials.json" : "/1/account/verify_credentials.json"),
+                this.CreateTwitterUri("/1.1/account/verify_credentials.json"),
                 null,
                 ref content,
-                this.apiStatusHeaders,
-                HttpTwitter.API11Enabled ? CreateApi11Calllback("/account/verify_credentials") : GetApiCallback);
+                this.CreateRatelimitHeadersDict(),
+                this.CreateApiCalllback("/account/verify_credentials"));
         }
 
         #region Proxy API
         private static string _twitterUrl = "api.twitter.com";
-        private static string _TwitterSearchUrl = "search.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));
-        }
-
-        private Uri CreateTwitterSearchUri(string path)
-        {
-            return new Uri(string.Format("{0}{1}{2}", _protocol, _TwitterSearchUrl, path));
+            return new Uri(string.Format("{0}{1}{2}", "https://", _twitterUrl, path));
         }
 
         private Uri CreateTwitterUserStreamUri(string path)
@@ -1023,36 +874,44 @@ namespace OpenTween
             return new Uri(string.Format("{0}{1}{2}", "http://", _twitterStreamUrl, path));
         }
 
-        public static string TwitterUrl
+        private Uri CreateTwitterUploadUri(string path)
         {
-            set
-            {
-                _twitterUrl = value;
-                HttpOAuthApiProxy.ProxyHost = value;
-            }
+            return new Uri(string.Format("{0}{1}{2}", "https://", _twitterUploadUrl, path));
         }
 
-        public static string TwitterSearchUrl
+        public static string TwitterUrl
         {
             set
             {
-                _TwitterSearchUrl = value;
+                _twitterUrl = value;
+                HttpOAuthApiProxy.ProxyHost = value;
             }
         }
         #endregion
 
-        private void GetApiCallback(Object sender, HttpStatusCode code, string content)
+        private Dictionary<string, string> CreateRatelimitHeadersDict()
         {
-            if (code < HttpStatusCode.InternalServerError)
-                MyCommon.TwitterApiInfo.UpdateFromHeader(this.apiStatusHeaders);
+            return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
+            {
+                {"X-Access-Level", ""},
+                {"X-RateLimit-Limit", ""},
+                {"X-RateLimit-Remaining", ""},
+                {"X-RateLimit-Reset", ""},
+                {"X-Rate-Limit-Limit", ""},
+                {"X-Rate-Limit-Remaining", ""},
+                {"X-Rate-Limit-Reset", ""},
+                {"X-MediaRateLimit-Limit", ""},
+                {"X-MediaRateLimit-Remaining", ""},
+                {"X-MediaRateLimit-Reset", ""},
+            };
         }
 
-        private CallbackDelegate CreateApi11Calllback(string endpointName)
+        private CallbackDelegate CreateApiCalllback(string endpointName)
         {
-            return (sender, code, content) =>
+            return (sender, code, headerInfo, content) =>
             {
                 if (code < HttpStatusCode.InternalServerError)
-                    MyCommon.TwitterApiInfo11.UpdateFromHeader(this.apiStatusHeaders, endpointName);
+                    MyCommon.TwitterApiInfo.UpdateFromHeader(headerInfo, endpointName);
             };
         }
 
@@ -1070,7 +929,7 @@ namespace OpenTween
                 param.Add("track", trackwords);
 
             return httpCon.GetContent(GetMethod,
-                CreateTwitterUserStreamUri(HttpTwitter.API11Enabled ? "/1.1/user.json" : "/2/user.json"),
+                this.CreateTwitterUserStreamUri("/1.1/user.json"),
                 param,
                 ref content,
                 userAgent);
@@ -1087,7 +946,7 @@ namespace OpenTween
                 param.Add("track", string.Join(",", trackwords.Split(" ".ToCharArray())));
 
             return httpCon.GetContent(PostMethod,
-                CreateTwitterStreamUri(HttpTwitter.API11Enabled ? "/1.1/statuses/filter.json" : "/1/statuses/filter.json"),
+                this.CreateTwitterStreamUri("/1.1/statuses/filter.json"),
                 param,
                 ref content,
                 userAgent);