}
[Fact]
+ public async Task ListsCreate_Test()
+ {
+ using (var twitterApi = new TwitterApi())
+ {
+ var mock = new Mock<IApiConnection>();
+ mock.Setup(x =>
+ x.PostLazyAsync<TwitterList>(
+ new Uri("lists/create.json", UriKind.Relative),
+ new Dictionary<string, string> {
+ { "name", "hogehoge" },
+ { "description", "aaaa" },
+ { "mode", "private" },
+ })
+ )
+ .ReturnsAsync(LazyJson.Create(new TwitterList()));
+
+ twitterApi.apiConnection = mock.Object;
+
+ await twitterApi.ListsCreate("hogehoge", description: "aaaa", @private: true)
+ .IgnoreResponse()
+ .ConfigureAwait(false);
+
+ mock.VerifyAll();
+ }
+ }
+
+ [Fact]
public async Task ListsStatuses_Test()
{
using (var twitterApi = new TwitterApi())
return this.apiConnection.GetAsync<TwitterLists>(endpoint, param, "/lists/subscriptions");
}
+ public Task<LazyJson<TwitterList>> ListsCreate(string name, string description = null, bool? @private = null)
+ {
+ var endpoint = new Uri("lists/create.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["name"] = name,
+ };
+
+ if (description != null)
+ param["description"] = description;
+ if (@private != null)
+ param["mode"] = @private.Value ? "private" : "public";
+
+ return this.apiConnection.PostLazyAsync<TwitterList>(endpoint, param);
+ }
+
public Task<TwitterStatus[]> ListsStatuses(long listId, int? count = null, long? maxId = null, long? sinceId = null, bool? includeRTs = null)
{
var endpoint = new Uri("lists/statuses.json", UriKind.Relative);
null);
}
- public HttpStatusCode CreateLists(string listname, Boolean isPrivate, string description, ref string content)
- {
- string mode = "public";
- if (isPrivate)
- mode = "private";
-
- Dictionary<string, string> param = new Dictionary<string, string>();
- param.Add("name", listname);
- param.Add("mode", mode);
- if (!string.IsNullOrEmpty(description))
- param.Add("description", description);
-
- return httpCon.GetContent(PostMethod,
- this.CreateTwitterUri("/1.1/lists/create.json"),
- param,
- ref content,
- null,
- null);
- }
-
public HttpStatusCode GetListMembers(string user, string list_id, long cursor, ref string content)
{
Dictionary<string, string> param = new Dictionary<string, string>();
// Boston, MA 02110-1301, USA.
using System.Collections.Generic;
+using System.Threading.Tasks;
using System.Xml.Serialization;
using OpenTween.Api.DataModel;
this._tw = tw;
}
- public virtual void Refresh()
+ public virtual async Task Refresh()
{
var newList = _tw.EditList(this.Id.ToString(), Name, !this.IsPublic, this.Description);
if (this.EditCheckBox.Checked == true) this.NameTextBox.Focus();
}
- private void OKEditButton_Click(object sender, EventArgs e)
+ private async void OKEditButton_Click(object sender, EventArgs e)
{
if (this.ListsList.SelectedItem == null) return;
- ListElement listItem = (ListElement) this.ListsList.SelectedItem;
- if (string.IsNullOrEmpty(this.NameTextBox.Text))
+ using (ControlTransaction.Disabled(this))
{
- MessageBox.Show(Properties.Resources.ListManageOKButton1);
- return;
- }
+ ListElement listItem = (ListElement)this.ListsList.SelectedItem;
+
+ if (string.IsNullOrEmpty(this.NameTextBox.Text))
+ {
+ MessageBox.Show(Properties.Resources.ListManageOKButton1);
+ return;
+ }
- listItem.Name = this.NameTextBox.Text;
- listItem.IsPublic = this.PublicRadioButton.Checked;
- listItem.Description = this.DescriptionText.Text;
+ listItem.Name = this.NameTextBox.Text;
+ listItem.IsPublic = this.PublicRadioButton.Checked;
+ listItem.Description = this.DescriptionText.Text;
- try
- {
- listItem.Refresh();
- }
- catch (WebApiException ex)
- {
- MessageBox.Show(string.Format(Properties.Resources.ListManageOKButton2, ex.Message));
- return;
- }
+ try
+ {
+ await listItem.Refresh();
+ }
+ catch (WebApiException ex)
+ {
+ MessageBox.Show(string.Format(Properties.Resources.ListManageOKButton2, ex.Message));
+ return;
+ }
- this.ListsList.Items.Clear();
- this.ListManage_Load(null, EventArgs.Empty);
+ this.ListsList.Items.Clear();
+ this.ListManage_Load(null, EventArgs.Empty);
- this.EditCheckBox.AutoCheck = true;
- this.EditCheckBox.Checked = false;
+ this.EditCheckBox.AutoCheck = true;
+ this.EditCheckBox.Checked = false;
+ }
}
private void CancelEditButton_Click(object sender, EventArgs e)
this._tw = tw;
}
- public override void Refresh()
+ public override async Task Refresh()
{
if (this.IsCreated)
{
- base.Refresh();
+ await base.Refresh().ConfigureAwait(false);
}
else
{
- this._tw.CreateListApi(this.Name, !this.IsPublic, this.Description);
+ await this._tw.CreateListApi(this.Name, !this.IsPublic, this.Description)
+ .ConfigureAwait(false);
+
this._isCreated = true;
}
}
}
}
- public void CreateListApi(string listName, bool isPrivate, string description)
+ public async Task CreateListApi(string listName, bool isPrivate, string description)
{
this.CheckAccountState();
- HttpStatusCode res;
- var content = "";
- try
- {
- res = twCon.CreateLists(listName, isPrivate, description, ref content);
- }
- catch(Exception ex)
- {
- throw new WebApiException("Err:" + ex.Message + "(" + MethodBase.GetCurrentMethod().Name + ")", ex);
- }
+ var response = await this.Api.ListsCreate(listName, description, isPrivate)
+ .ConfigureAwait(false);
- this.CheckStatusCode(res, content);
+ var list = await response.LoadJsonAsync()
+ .ConfigureAwait(false);
- try
- {
- var le = TwitterList.ParseJson(content);
- TabInformations.GetInstance().SubscribableLists.Add(new ListElement(le, this));
- }
- catch(SerializationException ex)
- {
- MyCommon.TraceOut(ex.Message + Environment.NewLine + content);
- throw new WebApiException("Err:Json Parse Error(DataContractJsonSerializer)", content, ex);
- }
- catch(Exception ex)
- {
- MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content);
- throw new WebApiException("Err:Invalid Json!", content, ex);
- }
+ TabInformations.GetInstance().SubscribableLists.Add(new ListElement(list, this));
}
public bool ContainsUserAtList(string listId, string user)