OSDN Git Service

/direct_messages/events/destroy.json のリクエスト形式の誤りを修正
authorKimura Youichi <kim.upsilon@bucyou.net>
Fri, 17 Aug 2018 04:14:56 +0000 (13:14 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Fri, 17 Aug 2018 04:15:50 +0000 (13:15 +0900)
Fixes: 1a38ae79 ("/direct_messages/events/destroy.json によるDMの削除に対応")

OpenTween.Tests/Connection/TwitterApiConnectionTest.cs
OpenTween/Api/TwitterApi.cs
OpenTween/Connection/IApiConnection.cs
OpenTween/Connection/TwitterApiConnection.cs

index dd1cf8d..c375f8e 100644 (file)
@@ -503,33 +503,18 @@ namespace OpenTween.Connection
             {
                 apiConnection.http = http;
 
-                mockHandler.Enqueue(async x =>
+                mockHandler.Enqueue(x =>
                 {
                     Assert.Equal(HttpMethod.Delete, x.Method);
                     Assert.Equal("https://api.twitter.com/1.1/hoge/tetete.json",
                         x.RequestUri.AbsoluteUri);
 
-                    var body = await x.Content.ReadAsStringAsync()
-                        .ConfigureAwait(false);
-                    var query = HttpUtility.ParseQueryString(body);
-
-                    Assert.Equal("1111", query["aaaa"]);
-                    Assert.Equal("2222", query["bbbb"]);
-
-                    return new HttpResponseMessage(HttpStatusCode.OK)
-                    {
-                        Content = new StringContent("\"hogehoge\""),
-                    };
+                    return new HttpResponseMessage(HttpStatusCode.NoContent);
                 });
 
                 var endpoint = new Uri("hoge/tetete.json", UriKind.Relative);
-                var param = new Dictionary<string, string>
-                {
-                    ["aaaa"] = "1111",
-                    ["bbbb"] = "2222",
-                };
 
-                await apiConnection.DeleteAsync(endpoint, param)
+                await apiConnection.DeleteAsync(endpoint)
                     .ConfigureAwait(false);
 
                 Assert.Equal(0, mockHandler.QueueCount);
index 0b535ae..e6b6d9a 100644 (file)
@@ -475,7 +475,10 @@ namespace OpenTween.Api
                 ["id"] = eventId.ToString(),
             };
 
-            return this.apiConnection.DeleteAsync(endpoint, param);
+            // なぜか application/x-www-form-urlencoded でパラメーターを送ると Bad Request になる謎仕様
+            endpoint = new Uri(endpoint.OriginalString + "?" + MyCommon.BuildQueryString(param), UriKind.Relative);
+
+            return this.apiConnection.DeleteAsync(endpoint);
         }
 
         public Task<TwitterUser> UsersShow(string screenName)
index 0cca640..3c9822a 100644 (file)
@@ -44,6 +44,6 @@ namespace OpenTween.Connection
 
         Task PostJsonAsync(Uri uri, string json);
 
-        Task DeleteAsync(Uri uri, IDictionary<string, string> param);
+        Task DeleteAsync(Uri uri);
     }
 }
index b8b015f..4340224 100644 (file)
@@ -329,33 +329,28 @@ namespace OpenTween.Connection
             }
         }
 
-        public async Task DeleteAsync(Uri uri, IDictionary<string, string> param)
+        public async Task DeleteAsync(Uri uri)
         {
             var requestUri = new Uri(RestApiBase, uri);
             var request = new HttpRequestMessage(HttpMethod.Delete, requestUri);
 
-            using (var postContent = new FormUrlEncodedContent(param))
+            try
             {
-                request.Content = postContent;
-
-                try
-                {
-                    using (var response = await this.http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead)
-                        .ConfigureAwait(false))
-                    {
-                        await this.CheckStatusCode(response)
-                            .ConfigureAwait(false);
-                    }
-                }
-                catch (HttpRequestException ex)
-                {
-                    throw TwitterApiException.CreateFromException(ex);
-                }
-                catch (OperationCanceledException ex)
+                using (var response = await this.http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead)
+                    .ConfigureAwait(false))
                 {
-                    throw TwitterApiException.CreateFromException(ex);
+                    await this.CheckStatusCode(response)
+                        .ConfigureAwait(false);
                 }
             }
+            catch (HttpRequestException ex)
+            {
+                throw TwitterApiException.CreateFromException(ex);
+            }
+            catch (OperationCanceledException ex)
+            {
+                throw TwitterApiException.CreateFromException(ex);
+            }
         }
 
         protected async Task CheckStatusCode(HttpResponseMessage response)