}
[Fact]
+ public async Task Configuration_Test()
+ {
+ using (var twitterApi = new TwitterApi())
+ {
+ var mock = new Mock<IApiConnection>();
+ mock.Setup(x =>
+ x.GetAsync<TwitterConfiguration>(
+ new Uri("help/configuration.json", UriKind.Relative),
+ null,
+ "/help/configuration")
+ )
+ .ReturnsAsync(new TwitterConfiguration());
+
+ twitterApi.apiConnection = mock.Object;
+
+ await twitterApi.Configuration()
+ .ConfigureAwait(false);
+
+ mock.VerifyAll();
+ }
+ }
+
+ [Fact]
public async Task MediaUpload_Test()
{
using (var twitterApi = new TwitterApi())
return this.apiConnection.PostLazyAsync<TwitterUser>(endpoint, param, paramMedia);
}
+ public Task<TwitterConfiguration> Configuration()
+ {
+ var endpoint = new Uri("help/configuration.json", UriKind.Relative);
+
+ return this.apiConnection.GetAsync<TwitterConfiguration>(endpoint, null, "/help/configuration");
+ }
+
public Task<LazyJson<TwitterUploadMediaResult>> MediaUpload(IMediaItem media)
{
var endpoint = new Uri("https://upload.twitter.com/1.1/media/upload.json");
this.CreateApiCalllback("/statuses/retweeters/ids"));
}
- public HttpStatusCode GetConfiguration(ref string content)
- {
- return httpCon.GetContent(GetMethod,
- this.CreateTwitterUri("/1.1/help/configuration.json"),
- null,
- ref content,
- this.CreateRatelimitHeadersDict(),
- this.CreateApiCalllback("/help/configuration"));
- }
-
public HttpStatusCode VerifyCredentials(ref string content)
{
return httpCon.GetContent(GetMethod,
await this.workerSemaphore.WaitAsync();
try
{
- await Task.Run(() => tw.RefreshConfiguration());
+ await this.tw.RefreshConfiguration();
if (this.tw.Configuration.PhotoSizeLimit != 0)
{
/// t.co の文字列長などの設定情報を更新します
/// </summary>
/// <exception cref="WebApiException"/>
- public void RefreshConfiguration()
+ public async Task RefreshConfiguration()
{
- this.Configuration = this.ConfigurationApi();
- }
-
- private TwitterConfiguration ConfigurationApi()
- {
- HttpStatusCode res;
- var content = "";
- try
- {
- res = twCon.GetConfiguration(ref content);
- }
- catch(Exception e)
- {
- throw new WebApiException("Err:" + e.Message + "(" + MethodBase.GetCurrentMethod().Name + ")", e);
- }
-
- this.CheckStatusCode(res, content);
-
- try
- {
- return TwitterConfiguration.ParseJson(content);
- }
- catch(SerializationException e)
- {
- var ex = new WebApiException("Err:Json Parse Error(DataContractJsonSerializer)", content, e);
- MyCommon.TraceOut(ex);
- throw ex;
- }
- catch(Exception e)
- {
- var ex = new WebApiException("Err:Invalid Json!", content, e);
- MyCommon.TraceOut(ex);
- throw ex;
- }
+ this.Configuration = await this.Api.Configuration()
+ .ConfigureAwait(false);
}
public void GetListsApi()