}
[Fact]
+ public async Task ListsMembers_Test()
+ {
+ using (var twitterApi = new TwitterApi())
+ {
+ var mock = new Mock<IApiConnection>();
+ mock.Setup(x =>
+ x.GetAsync<TwitterUsers>(
+ new Uri("lists/members.json", UriKind.Relative),
+ new Dictionary<string, string> {
+ { "list_id", "12345" },
+ { "include_entities", "true" },
+ { "include_ext_alt_text", "true" },
+ { "cursor", "-1" },
+ },
+ "/lists/members")
+ )
+ .ReturnsAsync(new TwitterUsers());
+
+ twitterApi.apiConnection = mock.Object;
+
+ await twitterApi.ListsMembers(12345L, cursor: -1)
+ .ConfigureAwait(false);
+
+ mock.VerifyAll();
+ }
+ }
+
+ [Fact]
public async Task DirectMessagesRecv_Test()
{
using (var twitterApi = new TwitterApi())
return this.apiConnection.GetAsync<TwitterStatus[]>(endpoint, param, "/lists/statuses");
}
+ public Task<TwitterUsers> ListsMembers(long listId, long? cursor = null)
+ {
+ var endpoint = new Uri("lists/members.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["list_id"] = listId.ToString(),
+ ["include_entities"] = "true",
+ ["include_ext_alt_text"] = "true",
+ };
+
+ if (cursor != null)
+ param["cursor"] = cursor.ToString();
+
+ return this.apiConnection.GetAsync<TwitterUsers>(endpoint, param, "/lists/members");
+ }
+
public Task<TwitterDirectMessage[]> DirectMessagesRecv(int? count = null, long? maxId = null, long? sinceId = null)
{
var endpoint = new Uri("direct_messages.json", UriKind.Relative);
}
#region Lists
- public HttpStatusCode GetListMembers(string user, string list_id, long cursor, ref string content)
- {
- Dictionary<string, string> param = new Dictionary<string, string>();
- param.Add("screen_name", user);
- param.Add("list_id", list_id);
- param.Add("cursor", cursor.ToString());
- return httpCon.GetContent(GetMethod,
- this.CreateTwitterUri("/1.1/lists/members.json"),
- param,
- ref content,
- this.CreateRatelimitHeadersDict(),
- this.CreateApiCalllback("/lists/members"));
- }
-
public HttpStatusCode CreateListMembers(string list_id, string memberName, ref string content)
{
Dictionary<string, string> param = new Dictionary<string, string>();
}
}
- public void RefreshMembers()
+ public async Task RefreshMembers()
{
var users = new List<UserInfo>();
- this._cursor = this._tw.GetListMembers(this.Id.ToString(), users, cursor: -1);
+ this._cursor = await this._tw.GetListMembers(this.Id, users, cursor: -1)
+ .ConfigureAwait(false);
this._members = users;
}
- public void GetMoreMembers()
+ public async Task GetMoreMembers()
{
- this._cursor = this._tw.GetListMembers(this.Id.ToString(), this._members, this._cursor);
+ this._cursor = await this._tw.GetListMembers(this.Id, this._members, this._cursor)
+ .ConfigureAwait(false);
}
public override string ToString()
var list = (ListElement)this.ListsList.SelectedItem;
try
{
- await Task.Run(() => list.RefreshMembers());
+ await list.RefreshMembers();
}
catch (WebApiException ex)
{
var list = (ListElement)this.ListsList.SelectedItem;
try
{
- await Task.Run(() => list.GetMoreMembers());
+ await list.GetMoreMembers();
}
catch (WebApiException ex)
{
return new ListElement(list, this);
}
- public long GetListMembers(string list_id, List<UserInfo> lists, long cursor)
+ public async Task<long> GetListMembers(long listId, List<UserInfo> lists, long cursor)
{
this.CheckAccountState();
- HttpStatusCode res;
- var content = "";
- try
- {
- res = twCon.GetListMembers(this.Username, list_id, cursor, ref content);
- }
- catch(Exception ex)
- {
- throw new WebApiException("Err:" + ex.Message);
- }
+ var users = await this.Api.ListsMembers(listId, cursor)
+ .ConfigureAwait(false);
- this.CheckStatusCode(res, content);
+ Array.ForEach(users.Users, u => lists.Add(new UserInfo(u)));
- try
- {
- var users = TwitterUsers.ParseJson(content);
- Array.ForEach<TwitterUser>(
- users.Users,
- u => lists.Add(new UserInfo(u)));
-
- return users.NextCursor;
- }
- 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);
- }
+ return users.NextCursor;
}
public async Task CreateListApi(string listName, bool isPrivate, string description)