}
[Fact]
- public async Task DirectMessagesDestroy_Test()
- {
- using (var twitterApi = new TwitterApi())
- {
- var mock = new Mock<IApiConnection>();
- mock.Setup(x =>
- x.PostLazyAsync<TwitterDirectMessage>(
- new Uri("direct_messages/destroy.json", UriKind.Relative),
- new Dictionary<string, string> { { "id", "100" } })
- )
- .ReturnsAsync(LazyJson.Create(new TwitterDirectMessage { Id = 100L }));
-
- twitterApi.apiConnection = mock.Object;
-
- await twitterApi.DirectMessagesDestroy(statusId: 100L)
- .IgnoreResponse()
- .ConfigureAwait(false);
-
- mock.VerifyAll();
- }
- }
-
- [Fact]
public async Task DirectMessagesEventsList_Test()
{
using (var twitterApi = new TwitterApi())
}
[Fact]
+ public async Task DirectMessagesEventsDestroy_Test()
+ {
+ using (var twitterApi = new TwitterApi())
+ {
+ var mock = new Mock<IApiConnection>();
+ mock.Setup(x =>
+ x.DeleteAsync(
+ new Uri("direct_messages/events/destroy.json", UriKind.Relative),
+ new Dictionary<string, string> { { "id", "100" } })
+ )
+ .Returns(Task.CompletedTask);
+
+ twitterApi.apiConnection = mock.Object;
+
+ await twitterApi.DirectMessagesEventsDestroy(eventId: "100")
+ .ConfigureAwait(false);
+
+ mock.VerifyAll();
+ }
+ }
+
+ [Fact]
public async Task UsersShow_Test()
{
using (var twitterApi = new TwitterApi())
Assert.Equal(0, mockHandler.QueueCount);
}
}
+
+ [Fact]
+ public async Task DeleteAsync_Test()
+ {
+ using (var mockHandler = new HttpMessageHandlerMock())
+ using (var http = new HttpClient(mockHandler))
+ using (var apiConnection = new TwitterApiConnection("", ""))
+ {
+ apiConnection.http = http;
+
+ mockHandler.Enqueue(async 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\""),
+ };
+ });
+
+ var endpoint = new Uri("hoge/tetete.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["aaaa"] = "1111",
+ ["bbbb"] = "2222",
+ };
+
+ await apiConnection.DeleteAsync(endpoint, param)
+ .ConfigureAwait(false);
+
+ Assert.Equal(0, mockHandler.QueueCount);
+ }
+ }
}
}
return this.apiConnection.GetAsync<TwitterDirectMessage[]>(endpoint, param, "/direct_messages/sent");
}
- public Task<LazyJson<TwitterDirectMessage>> DirectMessagesDestroy(long statusId)
- {
- var endpoint = new Uri("direct_messages/destroy.json", UriKind.Relative);
- var param = new Dictionary<string, string>
- {
- ["id"] = statusId.ToString(),
- };
-
- return this.apiConnection.PostLazyAsync<TwitterDirectMessage>(endpoint, param);
- }
-
public Task<TwitterMessageEventList> DirectMessagesEventsList(int? count = null, string cursor = null)
{
var endpoint = new Uri("direct_messages/events/list.json", UriKind.Relative);
return this.apiConnection.PostJsonAsync(endpoint, json);
}
+ public Task DirectMessagesEventsDestroy(string eventId)
+ {
+ var endpoint = new Uri("direct_messages/events/destroy.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["id"] = eventId.ToString(),
+ };
+
+ return this.apiConnection.DeleteAsync(endpoint, param);
+ }
+
public Task<TwitterUser> UsersShow(string screenName)
{
var endpoint = new Uri("users/show.json", UriKind.Relative);
Task PostAsync(Uri uri, IDictionary<string, string> param, IDictionary<string, IMediaItem> media);
Task PostJsonAsync(Uri uri, string json);
+
+ Task DeleteAsync(Uri uri, IDictionary<string, string> param);
}
}
}
}
+ public async Task DeleteAsync(Uri uri, IDictionary<string, string> param)
+ {
+ var requestUri = new Uri(RestApiBase, uri);
+ var request = new HttpRequestMessage(HttpMethod.Delete, requestUri);
+
+ using (var postContent = new FormUrlEncodedContent(param))
+ {
+ 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)
+ {
+ throw TwitterApiException.CreateFromException(ex);
+ }
+ }
+ }
+
protected async Task CheckStatusCode(HttpResponseMessage response)
{
var statusCode = response.StatusCode;
更新履歴
==== Ver 2.0.2-dev(2018/xx/xx)
- * NEW: DMの一覧取得について新APIに対応しました
+ * NEW: DMã\81®ä¸\80覧å\8f\96å¾\97ã\83»å\89\8aé\99¤ã\81«ã\81¤ã\81\84ã\81¦æ\96°APIã\81«å¯¾å¿\9cã\81\97ã\81¾ã\81\97ã\81\9f
* CHG: UserStreams停止によるエラーが発生した場合の再接続の間隔を10分に変更
==== Ver 2.0.1(2018/06/13)
{
if (post.IsDm)
{
- await this.twitterApi.DirectMessagesDestroy(post.StatusId)
- .IgnoreResponse();
+ await this.twitterApi.DirectMessagesEventsDestroy(post.StatusId.ToString(CultureInfo.InvariantCulture));
}
else
{