From 767b8277c54d7f36662f8bb6aa29415d664fabda Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Thu, 5 May 2016 14:05:14 +0900 Subject: [PATCH] =?utf8?q?HttpTwitter.DeleteListMembers=E3=83=A1=E3=82=BD?= =?utf8?q?=E3=83=83=E3=83=89=E3=82=92TwitterApi=E3=82=AF=E3=83=A9=E3=82=B9?= =?utf8?q?=E3=81=AB=E7=BD=AE=E3=81=8D=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- OpenTween.Tests/Api/TwitterApiTest.cs | 28 ++++++++++++++++++++++++++++ OpenTween/Api/TwitterApi.cs | 14 ++++++++++++++ OpenTween/Connection/HttpTwitter.cs | 15 --------------- OpenTween/ListManage.cs | 35 +++++++++++++++++++---------------- OpenTween/MyLists.cs | 2 +- OpenTween/Twitter.cs | 17 ----------------- 6 files changed, 62 insertions(+), 49 deletions(-) diff --git a/OpenTween.Tests/Api/TwitterApiTest.cs b/OpenTween.Tests/Api/TwitterApiTest.cs index 8453a201..5fc34891 100644 --- a/OpenTween.Tests/Api/TwitterApiTest.cs +++ b/OpenTween.Tests/Api/TwitterApiTest.cs @@ -528,6 +528,34 @@ namespace OpenTween.Api } [Fact] + public async Task ListsMembersDestroy_Test() + { + using (var twitterApi = new TwitterApi()) + { + var mock = new Mock(); + mock.Setup(x => + x.PostLazyAsync( + new Uri("lists/members/destroy.json", UriKind.Relative), + new Dictionary { + { "list_id", "12345" }, + { "screen_name", "twitterapi" }, + { "include_entities", "true" }, + { "include_ext_alt_text", "true" }, + }) + ) + .ReturnsAsync(LazyJson.Create(new TwitterUser())); + + twitterApi.apiConnection = mock.Object; + + await twitterApi.ListsMembersDestroy(12345L, "twitterapi") + .IgnoreResponse() + .ConfigureAwait(false); + + mock.VerifyAll(); + } + } + + [Fact] public async Task DirectMessagesRecv_Test() { using (var twitterApi = new TwitterApi()) diff --git a/OpenTween/Api/TwitterApi.cs b/OpenTween/Api/TwitterApi.cs index cbab0e4c..f78e415e 100644 --- a/OpenTween/Api/TwitterApi.cs +++ b/OpenTween/Api/TwitterApi.cs @@ -303,6 +303,20 @@ namespace OpenTween.Api return this.apiConnection.PostLazyAsync(endpoint, param); } + public Task> ListsMembersDestroy(long listId, string screenName) + { + var endpoint = new Uri("lists/members/destroy.json", UriKind.Relative); + var param = new Dictionary + { + ["list_id"] = listId.ToString(), + ["screen_name"] = screenName, + ["include_entities"] = "true", + ["include_ext_alt_text"] = "true", + }; + + return this.apiConnection.PostLazyAsync(endpoint, param); + } + public Task DirectMessagesRecv(int? count = null, long? maxId = null, long? sinceId = null) { var endpoint = new Uri("direct_messages.json", UriKind.Relative); diff --git a/OpenTween/Connection/HttpTwitter.cs b/OpenTween/Connection/HttpTwitter.cs index 64669925..d8b5ee5e 100644 --- a/OpenTween/Connection/HttpTwitter.cs +++ b/OpenTween/Connection/HttpTwitter.cs @@ -170,21 +170,6 @@ namespace OpenTween this.CreateApiCalllback("/saved_searches/list")); } - #region Lists - public HttpStatusCode DeleteListMembers(string list_id, string memberName, ref string content) - { - Dictionary param = new Dictionary(); - param.Add("screen_name", memberName); - param.Add("list_id", list_id); - return httpCon.GetContent(PostMethod, - this.CreateTwitterUri("/1.1/lists/members/destroy.json"), - param, - ref content, - null, - null); - } - #endregion - public HttpStatusCode Statusid_retweeted_by_ids(long statusid, int? count, int? page, ref string content) { Dictionary param = new Dictionary(); diff --git a/OpenTween/ListManage.cs b/OpenTween/ListManage.cs index 84d7c142..8f10f6d2 100644 --- a/OpenTween/ListManage.cs +++ b/OpenTween/ListManage.cs @@ -218,29 +218,32 @@ namespace OpenTween } } - private void DeleteUserButton_Click(object sender, EventArgs e) + private async void DeleteUserButton_Click(object sender, EventArgs e) { if (this.ListsList.SelectedItem == null || this.UserList.SelectedItem == null) return; - ListElement list = (ListElement) this.ListsList.SelectedItem; - UserInfo user = (UserInfo) this.UserList.SelectedItem; - if (MessageBox.Show(Properties.Resources.ListManageDeleteUser1, Application.ProductName, MessageBoxButtons.OKCancel) == DialogResult.OK) + using (ControlTransaction.Disabled(this)) { - try - { - this.tw.RemoveUserToList(list.Id.ToString(), user.Id.ToString()); - } - catch (WebApiException ex) + ListElement list = (ListElement)this.ListsList.SelectedItem; + UserInfo user = (UserInfo)this.UserList.SelectedItem; + if (MessageBox.Show(Properties.Resources.ListManageDeleteUser1, Application.ProductName, MessageBoxButtons.OKCancel) == DialogResult.OK) { - MessageBox.Show(string.Format(Properties.Resources.ListManageDeleteUser2, ex.Message)); - return; - } + try + { + await this.tw.Api.ListsMembersDestroy(list.Id, user.ScreenName); + } + catch (WebApiException ex) + { + MessageBox.Show(string.Format(Properties.Resources.ListManageDeleteUser2, ex.Message)); + return; + } - int idx = ListsList.SelectedIndex; - list.Members.Remove(user); - this.ListsList_SelectedIndexChanged(this.ListsList, EventArgs.Empty); - if (idx < ListsList.Items.Count) ListsList.SelectedIndex = idx; + int idx = ListsList.SelectedIndex; + list.Members.Remove(user); + this.ListsList_SelectedIndexChanged(this.ListsList, EventArgs.Empty); + if (idx < ListsList.Items.Count) ListsList.SelectedIndex = idx; + } } } diff --git a/OpenTween/MyLists.cs b/OpenTween/MyLists.cs index a1e36ae8..a6208cd9 100644 --- a/OpenTween/MyLists.cs +++ b/OpenTween/MyLists.cs @@ -180,7 +180,7 @@ namespace OpenTween await this._tw.Api.ListsMembersCreate(list.Id, this.contextUserName); break; case CheckState.Checked: - this._tw.RemoveUserToList(list.Id.ToString(), this.contextUserName.ToString()); + await this._tw.Api.ListsMembersDestroy(list.Id, this.contextUserName); break; } } diff --git a/OpenTween/Twitter.cs b/OpenTween/Twitter.cs index 3ce44333..faaf374f 100644 --- a/OpenTween/Twitter.cs +++ b/OpenTween/Twitter.cs @@ -1736,23 +1736,6 @@ namespace OpenTween } } - public void RemoveUserToList(string listId, string user) - { - HttpStatusCode res; - var content = ""; - - try - { - res = twCon.DeleteListMembers(listId, user, ref content); - } - catch(Exception ex) - { - throw new WebApiException("Err:" + ex.Message + "(" + MethodBase.GetCurrentMethod().Name + ")", ex); - } - - this.CheckStatusCode(res, content); - } - public string CreateHtmlAnchor(string text, List AtList, TwitterEntities entities, List media) { if (entities != null) -- 2.11.0