private async Task<Uri> ShortenByUxnuAsync(Uri srcUri)
{
// 明らかに長くなると推測できる場合は短縮しない
if ("http://ux.nx/xxxxxx".Length > srcUri.OriginalString.Length)
return srcUri;
var query = new Dictionary<string, string>
{
["format"] = "plain",
["url"] = srcUri.OriginalString,
};
var uri = new Uri("http://ux.nu/api/short?" + MyCommon.BuildQueryString(query));
using (var response = await this.http.GetAsync(uri).ConfigureAwait(false))
{
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadAsStringAsync()
.ConfigureAwait(false);
if (!Regex.IsMatch(result, @"^https?://"))
throw new WebApiException("Failed to create URL.", result);
return new Uri(result.TrimEnd());
}
}