}
[Fact]
+ public async Task StatusesHomeTimeline_Test()
+ {
+ using (var twitterApi = new TwitterApi())
+ {
+ var mock = new Mock<IApiConnection>();
+ mock.Setup(x =>
+ x.GetAsync<TwitterStatus[]>(
+ new Uri("statuses/home_timeline.json", UriKind.Relative),
+ new Dictionary<string, string> {
+ { "include_entities", "true" },
+ { "include_ext_alt_text", "true" },
+ { "count", "200" },
+ { "max_id", "900" },
+ { "since_id", "100" },
+ },
+ "/statuses/home_timeline")
+ )
+ .ReturnsAsync(new TwitterStatus[0]);
+
+ twitterApi.apiConnection = mock.Object;
+
+ await twitterApi.StatusesHomeTimeline(200, maxId: 900L, sinceId: 100L)
+ .ConfigureAwait(false);
+
+ mock.VerifyAll();
+ }
+ }
+
+ [Fact]
+ public async Task StatusesMentionsTimeline_Test()
+ {
+ using (var twitterApi = new TwitterApi())
+ {
+ var mock = new Mock<IApiConnection>();
+ mock.Setup(x =>
+ x.GetAsync<TwitterStatus[]>(
+ new Uri("statuses/mentions_timeline.json", UriKind.Relative),
+ new Dictionary<string, string> {
+ { "include_entities", "true" },
+ { "include_ext_alt_text", "true" },
+ { "count", "200" },
+ { "max_id", "900" },
+ { "since_id", "100" },
+ },
+ "/statuses/mentions_timeline")
+ )
+ .ReturnsAsync(new TwitterStatus[0]);
+
+ twitterApi.apiConnection = mock.Object;
+
+ await twitterApi.StatusesMentionsTimeline(200, maxId: 900L, sinceId: 100L)
+ .ConfigureAwait(false);
+
+ mock.VerifyAll();
+ }
+ }
+
+ [Fact]
public async Task StatusesShow_Test()
{
using (var twitterApi = new TwitterApi())
this.CurrentScreenName = screenName;
}
+ public Task<TwitterStatus[]> StatusesHomeTimeline(int? count = null, long? maxId = null, long? sinceId = null)
+ {
+ var endpoint = new Uri("statuses/home_timeline.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["include_entities"] = "true",
+ ["include_ext_alt_text"] = "true",
+ };
+
+ if (count != null)
+ param["count"] = count.ToString();
+ if (maxId != null)
+ param["max_id"] = maxId.ToString();
+ if (sinceId != null)
+ param["since_id"] = sinceId.ToString();
+
+ return this.apiConnection.GetAsync<TwitterStatus[]>(endpoint, param, "/statuses/home_timeline");
+ }
+
+ public Task<TwitterStatus[]> StatusesMentionsTimeline(int? count = null, long? maxId = null, long? sinceId = null)
+ {
+ var endpoint = new Uri("statuses/mentions_timeline.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["include_entities"] = "true",
+ ["include_ext_alt_text"] = "true",
+ };
+
+ if (count != null)
+ param["count"] = count.ToString();
+ if (maxId != null)
+ param["max_id"] = maxId.ToString();
+ if (sinceId != null)
+ param["since_id"] = sinceId.ToString();
+
+ return this.apiConnection.GetAsync<TwitterStatus[]>(endpoint, param, "/statuses/mentions_timeline");
+ }
+
public Task<TwitterStatus> StatusesShow(long statusId)
{
var endpoint = new Uri("statuses/show.json", UriKind.Relative);
this.Initialize("", "", "", 0);
}
- public HttpStatusCode HomeTimeline(int? count, long? max_id, long? since_id, ref string content)
- {
- Dictionary<string, string> param = new Dictionary<string, string>();
- if (count != null)
- param.Add("count", count.ToString());
- if (max_id != null)
- param.Add("max_id", max_id.ToString());
- if (since_id != null)
- param.Add("since_id", since_id.ToString());
-
- param.Add("include_entities", "true");
- param.Add("include_ext_alt_text", "true");
-
- return httpCon.GetContent(GetMethod,
- this.CreateTwitterUri("/1.1/statuses/home_timeline.json"),
- param,
- ref content,
- this.CreateRatelimitHeadersDict(),
- this.CreateApiCalllback("/statuses/home_timeline"));
- }
-
public HttpStatusCode UserTimeline(long? user_id, string screen_name, int? count, long? max_id, long? since_id, ref string content)
{
Dictionary<string, string> param = new Dictionary<string, string>();
this.CreateApiCalllback("/statuses/user_timeline"));
}
- public HttpStatusCode Mentions(int? count, long? max_id, long? since_id, ref string content)
- {
- Dictionary<string, string> param = new Dictionary<string, string>();
- if (count != null)
- param.Add("count", count.ToString());
- if (max_id != null)
- param.Add("max_id", max_id.ToString());
- if (since_id != null)
- param.Add("since_id", since_id.ToString());
-
- param.Add("include_entities", "true");
- param.Add("include_ext_alt_text", "true");
-
- return httpCon.GetContent(GetMethod,
- this.CreateTwitterUri("/1.1/statuses/mentions_timeline.json"),
- param,
- ref content,
- this.CreateRatelimitHeadersDict(),
- this.CreateApiCalllback("/statuses/mentions_timeline"));
- }
-
public HttpStatusCode DirectMessages(int? count, long? max_id, long? since_id, ref string content)
{
Dictionary<string, string> param = new Dictionary<string, string>();
catch (WebApiException ex)
{
this._myStatusError = true;
- this.StatusLabel.Text = ex.Message;
+ this.StatusLabel.Text = $"Err:{ex.Message}(GetTimeline)";
}
finally
{
p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText5, loadMore ? -1 : 1));
- await Task.Run(() =>
+ await Task.Run(async () =>
{
- this.tw.GetTimelineApi(read, MyCommon.WORKERTYPE.Timeline, loadMore, this._initial);
+ await this.tw.GetTimelineApi(read, MyCommon.WORKERTYPE.Timeline, loadMore, this._initial)
+ .ConfigureAwait(false);
// 新着時未読クリア
if (this._cfgCommon.ReadOldPosts)
catch (WebApiException ex)
{
this._myStatusError = true;
- this.StatusLabel.Text = ex.Message;
+ this.StatusLabel.Text = $"Err:{ex.Message}(GetTimeline)";
}
finally
{
p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText4, loadMore ? -1 : 1));
- await Task.Run(() =>
+ await Task.Run(async () =>
{
- this.tw.GetTimelineApi(read, MyCommon.WORKERTYPE.Reply, loadMore, this._initial);
+ await this.tw.GetTimelineApi(read, MyCommon.WORKERTYPE.Reply, loadMore, this._initial)
+ .ConfigureAwait(false);
this._statuses.DistributePosts();
});
return Math.Min(count, GetMaxApiResultCount(type));
}
- public void GetTimelineApi(bool read,
- MyCommon.WORKERTYPE gType,
- bool more,
- bool startup)
+ public async Task GetTimelineApi(bool read, MyCommon.WORKERTYPE gType, bool more, bool startup)
{
this.CheckAccountState();
- HttpStatusCode res;
- var content = "";
var count = GetApiResultCount(gType, more, startup);
- try
+ TwitterStatus[] statuses;
+ if (gType == MyCommon.WORKERTYPE.Timeline)
{
- if (gType == MyCommon.WORKERTYPE.Timeline)
+ if (more)
{
- if (more)
- {
- res = twCon.HomeTimeline(count, this.minHomeTimeline, null, ref content);
- }
- else
- {
- res = twCon.HomeTimeline(count, null, null, ref content);
- }
+ statuses = await this.Api.StatusesHomeTimeline(count, maxId: this.minHomeTimeline)
+ .ConfigureAwait(false);
}
else
{
- if (more)
- {
- res = twCon.Mentions(count, this.minMentions, null, ref content);
- }
- else
- {
- res = twCon.Mentions(count, null, null, ref content);
- }
+ statuses = await this.Api.StatusesHomeTimeline(count)
+ .ConfigureAwait(false);
}
}
- catch(Exception ex)
+ else
{
- throw new WebApiException("Err:" + ex.Message, ex);
+ if (more)
+ {
+ statuses = await this.Api.StatusesMentionsTimeline(count, maxId: this.minMentions)
+ .ConfigureAwait(false);
+ }
+ else
+ {
+ statuses = await this.Api.StatusesMentionsTimeline(count)
+ .ConfigureAwait(false);
+ }
}
- this.CheckStatusCode(res, content);
-
- var minimumId = CreatePostsFromJson(content, gType, null, read);
+ var minimumId = CreatePostsFromJson(statuses, gType, null, read);
if (minimumId != null)
{
throw new WebApiException("Invalid Json!", content, ex);
}
+ return this.CreatePostsFromJson(items, gType, tab, read);
+ }
+
+ private long? CreatePostsFromJson(TwitterStatus[] items, MyCommon.WORKERTYPE gType, TabClass tab, bool read)
+ {
long? minimumId = null;
foreach (var status in items)