OSDN Git Service

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

index 73d9e85..869d8b6 100644 (file)
@@ -378,6 +378,29 @@ namespace OpenTween.Api
         }
 
         [Fact]
+        public async Task NoRetweetIds_Test()
+        {
+            using (var twitterApi = new TwitterApi())
+            {
+                var mock = new Mock<IApiConnection>();
+                mock.Setup(x =>
+                    x.GetAsync<long[]>(
+                        new Uri("friendships/no_retweets/ids.json", UriKind.Relative),
+                        null,
+                        "/friendships/no_retweets/ids")
+                )
+                .ReturnsAsync(new long[0]);
+
+                twitterApi.apiConnection = mock.Object;
+
+                await twitterApi.NoRetweetIds()
+                    .ConfigureAwait(false);
+
+                mock.VerifyAll();
+            }
+        }
+
+        [Fact]
         public async Task FollowersIds_Test()
         {
             using (var twitterApi = new TwitterApi())
index 030ff11..b5d2606 100644 (file)
@@ -192,6 +192,13 @@ namespace OpenTween.Api
             return this.apiConnection.PostLazyAsync<TwitterFriendship>(endpoint, param);
         }
 
+        public Task<long[]> NoRetweetIds(long? cursor = null)
+        {
+            var endpoint = new Uri("friendships/no_retweets/ids.json", UriKind.Relative);
+
+            return this.apiConnection.GetAsync<long[]>(endpoint, null, "/friendships/no_retweets/ids");
+        }
+
         public Task<TwitterIds> FollowersIds(long? cursor = null)
         {
             var endpoint = new Uri("followers/ids.json", UriKind.Relative);
index b440ba7..42f13a9 100644 (file)
@@ -328,16 +328,6 @@ namespace OpenTween
                 this.CreateApiCalllback("/saved_searches/list"));
         }
 
-        public HttpStatusCode NoRetweetIds(ref string content)
-        {
-            return httpCon.GetContent(GetMethod,
-                this.CreateTwitterUri("/1.1/friendships/no_retweets/ids.json"),
-                null,
-                ref content,
-                this.CreateRatelimitHeadersDict(),
-                this.CreateApiCalllback("/friendships/no_retweets/ids"));
-        }
-
         public HttpStatusCode RateLimitStatus(ref string content)
         {
             return httpCon.GetContent(GetMethod,
index 20e2387..7bb2b0c 100644 (file)
@@ -3283,7 +3283,7 @@ namespace OpenTween
             await this.workerSemaphore.WaitAsync();
             try
             {
-                await Task.Run(() => tw.RefreshNoRetweetIds());
+                await this.tw.RefreshNoRetweetIds();
 
                 this.StatusLabel.Text = "NoRetweetIds refreshed";
             }
index 7eb5887..b944a01 100644 (file)
@@ -1787,50 +1787,16 @@ namespace OpenTween
         /// RT 非表示ユーザーを更新します
         /// </summary>
         /// <exception cref="WebApiException"/>
-        public void RefreshNoRetweetIds()
+        public async Task RefreshNoRetweetIds()
         {
             if (MyCommon._endingFlag) return;
 
-            this.noRTId = this.NoRetweetIdsApi();
+            this.noRTId = await this.Api.NoRetweetIds()
+                .ConfigureAwait(false);
 
             this._GetNoRetweetResult = true;
         }
 
-        private long[] NoRetweetIdsApi()
-        {
-            this.CheckAccountState();
-
-            HttpStatusCode res;
-            var content = "";
-            try
-            {
-                res = twCon.NoRetweetIds(ref content);
-            }
-            catch(Exception e)
-            {
-                throw new WebApiException("Err:" + e.Message + "(" + MethodBase.GetCurrentMethod().Name + ")", e);
-            }
-
-            this.CheckStatusCode(res, content);
-
-            try
-            {
-                return MyCommon.CreateDataFromJson<long[]>(content);
-            }
-            catch(SerializationException e)
-            {
-                var ex = new WebApiException("Err:Json Parse Error(DataContractJsonSerializer)", content, e);
-                MyCommon.TraceOut(ex);
-                throw ex;
-            }
-            catch(Exception e)
-            {
-                var ex = new WebApiException("Err:Invalid Json!", content, e);
-                MyCommon.TraceOut(ex);
-                throw ex;
-            }
-        }
-
         public bool GetNoRetweetSuccess
         {
             get