OSDN Git Service

HttpTwitter.DeleteListIDメソッドをTwitterApiクラスに置き換え
authorKimura Youichi <kim.upsilon@bucyou.net>
Wed, 4 May 2016 17:17:05 +0000 (02:17 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Wed, 4 May 2016 19:15:51 +0000 (04:15 +0900)
OpenTween.Tests/Api/TwitterApiTest.cs
OpenTween/Api/TwitterApi.cs
OpenTween/Connection/HttpTwitter.cs
OpenTween/ListManage.cs
OpenTween/Twitter.cs

index 176bd72..3ab22f1 100644 (file)
@@ -388,6 +388,31 @@ namespace OpenTween.Api
         }
 
         [Fact]
+        public async Task ListsDestroy_Test()
+        {
+            using (var twitterApi = new TwitterApi())
+            {
+                var mock = new Mock<IApiConnection>();
+                mock.Setup(x =>
+                    x.PostLazyAsync<TwitterList>(
+                        new Uri("lists/destroy.json", UriKind.Relative),
+                        new Dictionary<string, string> {
+                            { "list_id", "12345" },
+                        })
+                )
+                .ReturnsAsync(LazyJson.Create(new TwitterList()));
+
+                twitterApi.apiConnection = mock.Object;
+
+                await twitterApi.ListsDestroy(12345L)
+                    .IgnoreResponse()
+                    .ConfigureAwait(false);
+
+                mock.VerifyAll();
+            }
+        }
+
+        [Fact]
         public async Task ListsStatuses_Test()
         {
             using (var twitterApi = new TwitterApi())
index 672a8f3..3104e1e 100644 (file)
@@ -226,6 +226,17 @@ namespace OpenTween.Api
             return this.apiConnection.PostLazyAsync<TwitterList>(endpoint, param);
         }
 
+        public Task<LazyJson<TwitterList>> ListsDestroy(long listId)
+        {
+            var endpoint = new Uri("lists/destroy.json", UriKind.Relative);
+            var param = new Dictionary<string, string>
+            {
+                ["list_id"] = listId.ToString(),
+            };
+
+            return this.apiConnection.PostLazyAsync<TwitterList>(endpoint, param);
+        }
+
         public Task<TwitterStatus[]> ListsStatuses(long listId, int? count = null, long? maxId = null, long? sinceId = null, bool? includeRTs = null)
         {
             var endpoint = new Uri("lists/statuses.json", UriKind.Relative);
index 977e252..9f7a372 100644 (file)
@@ -201,20 +201,6 @@ namespace OpenTween
         }
 
         #region Lists
-        public HttpStatusCode DeleteListID(string user, string list_id, ref string content)
-        {
-            Dictionary<string, string> param = new Dictionary<string, string>();
-            param.Add("screen_name", user);
-            param.Add("list_id", list_id);
-
-            return httpCon.GetContent(PostMethod,
-                this.CreateTwitterUri("/1.1/lists/destroy.json"),
-                param,
-                ref content,
-                null,
-                null);
-        }
-
         public HttpStatusCode GetListMembers(string user, string list_id, long cursor, ref string content)
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
index 7633466..6820b41 100644 (file)
@@ -256,7 +256,7 @@ namespace OpenTween
                 {
                     try
                     {
-                        this.tw.DeleteList(list.Id.ToString());
+                        await this.tw.DeleteList(list.Id);
                     }
                     catch (WebApiException ex)
                     {
index 1e0b225..e83d6c5 100644 (file)
@@ -1729,21 +1729,17 @@ namespace OpenTween
                 .ToList();
         }
 
-        public void DeleteList(string list_id)
+        public async Task DeleteList(long listId)
         {
-            HttpStatusCode res;
-            var content = "";
+            await this.Api.ListsDestroy(listId)
+                .IgnoreResponse()
+                .ConfigureAwait(false);
 
-            try
-            {
-                res = twCon.DeleteListID(this.Username, list_id, ref content);
-            }
-            catch(Exception ex)
-            {
-                throw new WebApiException("Err:" + ex.Message + "(" + MethodBase.GetCurrentMethod().Name + ")", ex);
-            }
+            var tabinfo = TabInformations.GetInstance();
 
-            this.CheckStatusCode(res, content);
+            tabinfo.SubscribableLists = tabinfo.SubscribableLists
+                .Where(x => x.Id != listId)
+                .ToList();
         }
 
         public async Task<ListElement> EditList(long listId, string new_name, bool isPrivate, string description)