}
[Fact]
- public async Task DirectMessagesNew_Test()
+ 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/new.json", UriKind.Relative),
- new Dictionary<string, string> {
- { "text", "hogehoge" },
- { "screen_name", "opentween" },
- })
+ new Uri("direct_messages/destroy.json", UriKind.Relative),
+ new Dictionary<string, string> { { "id", "100" } })
)
- .ReturnsAsync(LazyJson.Create(new TwitterDirectMessage()));
+ .ReturnsAsync(LazyJson.Create(new TwitterDirectMessage { Id = 100L }));
twitterApi.apiConnection = mock.Object;
- await twitterApi.DirectMessagesNew("hogehoge", "opentween")
+ await twitterApi.DirectMessagesDestroy(statusId: 100L)
.IgnoreResponse()
.ConfigureAwait(false);
}
[Fact]
- public async Task DirectMessagesDestroy_Test()
+ public async Task DirectMessagesEventsNew_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" } })
+ x.PostJsonAsync(
+ new Uri("direct_messages/events/new.json", UriKind.Relative),
+ @"{
+ ""event"": {
+ ""type"": ""message_create"",
+ ""message_create"": {
+ ""target"": {
+ ""recipient_id"": ""12345""
+ },
+ ""message_data"": {
+ ""text"": ""hogehoge""
+ }
+ }
+ }
+}")
)
- .ReturnsAsync(LazyJson.Create(new TwitterDirectMessage { Id = 100L }));
+ .Returns(Task.FromResult(0));
twitterApi.apiConnection = mock.Object;
- await twitterApi.DirectMessagesDestroy(statusId: 100L)
- .IgnoreResponse()
+ await twitterApi.DirectMessagesEventsNew(recipientId: 12345L, text: "hogehoge")
.ConfigureAwait(false);
mock.VerifyAll();
return this.apiConnection.GetAsync<TwitterDirectMessage[]>(endpoint, param, "/direct_messages/sent");
}
- public Task<LazyJson<TwitterDirectMessage>> DirectMessagesNew(string status, string sendTo)
+ public Task<LazyJson<TwitterDirectMessage>> DirectMessagesDestroy(long statusId)
{
- var endpoint = new Uri("direct_messages/new.json", UriKind.Relative);
+ var endpoint = new Uri("direct_messages/destroy.json", UriKind.Relative);
var param = new Dictionary<string, string>
{
- ["text"] = status,
- ["screen_name"] = sendTo,
+ ["id"] = statusId.ToString(),
};
return this.apiConnection.PostLazyAsync<TwitterDirectMessage>(endpoint, param);
}
- public Task<LazyJson<TwitterDirectMessage>> DirectMessagesDestroy(long statusId)
+ public Task DirectMessagesEventsNew(long recipientId, string text)
{
- var endpoint = new Uri("direct_messages/destroy.json", UriKind.Relative);
- var param = new Dictionary<string, string>
- {
- ["id"] = statusId.ToString(),
- };
+ var endpoint = new Uri("direct_messages/events/new.json", UriKind.Relative);
- return this.apiConnection.PostLazyAsync<TwitterDirectMessage>(endpoint, param);
+ var json = $@"{{
+ ""event"": {{
+ ""type"": ""message_create"",
+ ""message_create"": {{
+ ""target"": {{
+ ""recipient_id"": ""{EscapeJsonString(recipientId.ToString())}""
+ }},
+ ""message_data"": {{
+ ""text"": ""{EscapeJsonString(text)}""
+ }}
+ }}
+ }}
+}}";
+
+ return this.apiConnection.PostJsonAsync(endpoint, json);
}
public Task<TwitterUser> UsersShow(string screenName)
<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
var mc = Twitter.DMSendTextRegex.Match(postStr);
- var response = await this.Api.DirectMessagesNew(mc.Groups["body"].Value, mc.Groups["id"].Value)
- .ConfigureAwait(false);
+ var body = mc.Groups["body"].Value;
+ var recipientName = mc.Groups["id"].Value;
- var dm = await response.LoadJsonAsync()
+ var recipient = await this.Api.UsersShow(recipientName)
.ConfigureAwait(false);
- this.UpdateUserStats(dm.Sender);
+ await this.Api.DirectMessagesEventsNew(recipient.Id, body)
+ .ConfigureAwait(false);
}
public async Task PostRetweet(long id, bool read)