OSDN Git Service

HttpTwitter.GetListsStatusesメソッドをTwitterApiクラスに置き換え
authorKimura Youichi <kim.upsilon@bucyou.net>
Sat, 30 Apr 2016 17:20:56 +0000 (02:20 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 30 Apr 2016 18:11:39 +0000 (03:11 +0900)
OpenTween.Tests/Api/TwitterApiTest.cs
OpenTween/Api/TwitterApi.cs
OpenTween/Connection/HttpTwitter.cs
OpenTween/Tween.cs
OpenTween/Twitter.cs

index 6bc80d4..f42d827 100644 (file)
@@ -280,6 +280,37 @@ namespace OpenTween.Api
         }
 
         [Fact]
+        public async Task ListsStatuses_Test()
+        {
+            using (var twitterApi = new TwitterApi())
+            {
+                var mock = new Mock<IApiConnection>();
+                mock.Setup(x =>
+                    x.GetAsync<TwitterStatus[]>(
+                        new Uri("lists/statuses.json", UriKind.Relative),
+                        new Dictionary<string, string> {
+                            { "list_id", "12345" },
+                            { "include_entities", "true" },
+                            { "include_ext_alt_text", "true" },
+                            { "count", "200" },
+                            { "max_id", "900" },
+                            { "since_id", "100" },
+                            { "include_rts", "true" },
+                        },
+                        "/lists/statuses")
+                )
+                .ReturnsAsync(new TwitterStatus[0]);
+
+                twitterApi.apiConnection = mock.Object;
+
+                await twitterApi.ListsStatuses(12345L, count: 200, maxId: 900L, sinceId: 100L, includeRTs: true)
+                    .ConfigureAwait(false);
+
+                mock.VerifyAll();
+            }
+        }
+
+        [Fact]
         public async Task DirectMessagesNew_Test()
         {
             using (var twitterApi = new TwitterApi())
index 179974c..2eff941 100644 (file)
@@ -161,6 +161,28 @@ namespace OpenTween.Api
             return this.apiConnection.PostLazyAsync<TwitterStatus>(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);
+            var param = new Dictionary<string, string>
+            {
+                ["list_id"] = listId.ToString(),
+                ["include_entities"] = "true",
+                ["include_ext_alt_text"] = "true",
+            };
+
+            if (count != null)
+                param["count"] = count.ToString();
+            if (maxId != null)
+                param["max_id"] = maxId.ToString();
+            if (sinceId != null)
+                param["since_id"] = sinceId.ToString();
+            if (includeRTs != null)
+                param["include_rts"] = includeRTs.Value ? "true" : "false";
+
+            return this.apiConnection.GetAsync<TwitterStatus[]>(endpoint, param, "/lists/statuses");
+        }
+
         public Task<LazyJson<TwitterDirectMessage>> DirectMessagesNew(string status, string sendTo)
         {
             var endpoint = new Uri("direct_messages/new.json", UriKind.Relative);
index 34f25dd..4d738ee 100644 (file)
@@ -314,30 +314,6 @@ namespace OpenTween
                 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)
-        {
-            //認証なくても取得できるが、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 != null)
-                param.Add("count", per_page.ToString());
-            if (max_id != null)
-                param.Add("max_id", max_id.ToString());
-            if (since_id != null)
-                param.Add("since_id", since_id.ToString());
-            param.Add("include_entities", "true");
-            param.Add("include_ext_alt_text", "true");
-
-            return httpCon.GetContent(GetMethod,
-                this.CreateTwitterUri("/1.1/lists/statuses.json"),
-                param,
-                ref content,
-                this.CreateRatelimitHeadersDict(),
-                this.CreateApiCalllback("/lists/statuses"));
-        }
-
         public HttpStatusCode CreateLists(string listname, Boolean isPrivate, string description, ref string content)
         {
             string mode = "public";
index a759bf4..ccaba4f 100644 (file)
@@ -2714,7 +2714,7 @@ namespace OpenTween
             catch (WebApiException ex)
             {
                 this._myStatusError = true;
-                this.StatusLabel.Text = ex.Message;
+                this.StatusLabel.Text = $"Err:{ex.Message}(GetListStatus)";
             }
             finally
             {
@@ -2738,7 +2738,7 @@ namespace OpenTween
 
             p.Report("List refreshing...");
 
-            await Task.Run(() =>
+            await Task.Run(async () =>
             {
                 WebApiException lastException = null;
 
@@ -2749,7 +2749,8 @@ namespace OpenTween
                         if (tab.ListInfo == null || tab.ListInfo.Id == 0)
                             continue;
 
-                        this.tw.GetListStatus(read, tab, loadMore, this._initial);
+                        await this.tw.GetListStatus(read, tab, loadMore, this._initial)
+                            .ConfigureAwait(false);
                     }
                     catch (WebApiException ex)
                     {
index cb44903..89e50a9 100644 (file)
@@ -1288,34 +1288,23 @@ namespace OpenTween
             }
         }
 
-        public void GetListStatus(bool read,
-                                TabClass tab,
-                                bool more,
-                                bool startup)
+        public async Task GetListStatus(bool read, TabClass tab, bool more, bool startup)
         {
-            HttpStatusCode res;
-            var content = "";
             var count = GetApiResultCount(MyCommon.WORKERTYPE.List, more, startup);
 
-            try
+            TwitterStatus[] statuses;
+            if (more)
             {
-                if (more)
-                {
-                    res = twCon.GetListsStatuses(tab.ListInfo.UserId, tab.ListInfo.Id, count, tab.OldestId, null, SettingCommon.Instance.IsListsIncludeRts, ref content);
-                }
-                else
-                {
-                    res = twCon.GetListsStatuses(tab.ListInfo.UserId, tab.ListInfo.Id, count, null, null, SettingCommon.Instance.IsListsIncludeRts, ref content);
-                }
+                statuses = await this.Api.ListsStatuses(tab.ListInfo.Id, count, maxId: tab.OldestId, includeRTs: SettingCommon.Instance.IsListsIncludeRts)
+                    .ConfigureAwait(false);
             }
-            catch(Exception ex)
+            else
             {
-                throw new WebApiException("Err:" + ex.Message, ex);
+                statuses = await this.Api.ListsStatuses(tab.ListInfo.Id, count, includeRTs: SettingCommon.Instance.IsListsIncludeRts)
+                    .ConfigureAwait(false);
             }
 
-            this.CheckStatusCode(res, content);
-
-            var minimumId = CreatePostsFromJson(content, MyCommon.WORKERTYPE.List, tab, read);
+            var minimumId = CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.List, tab, read);
 
             if (minimumId != null)
                 tab.OldestId = minimumId.Value;