{
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);
["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)
Task PostJsonAsync(Uri uri, string json);
- Task DeleteAsync(Uri uri, IDictionary<string, string> param);
+ Task DeleteAsync(Uri uri);
}
}
}
}
- 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)