OSDN Git Service

null値の比較を簡略化する (IDE0031, IDE0041)
[opentween/open-tween.git] / OpenTween / Thumbnail / Services / Tinami.cs
index df7c569..e1eb573 100644 (file)
@@ -30,19 +30,30 @@ using System.Threading.Tasks;
 using System.Web;
 using System.Xml.Linq;
 using System.Xml.XPath;
+using OpenTween.Connection;
+using OpenTween.Models;
 
 namespace OpenTween.Thumbnail.Services
 {
     class Tinami : IThumbnailService
     {
         public static readonly Regex UrlPatternRegex =
-            new Regex(@"^http://www\.tinami\.com/view/(?<ContentId>\d+)$");
+            new Regex(@"^https?://www\.tinami\.com/view/(?<ContentId>\d+)$");
 
-        protected readonly HttpClient http;
+        protected HttpClient http
+        {
+            get { return this.localHttpClient ?? Networking.Http; }
+        }
+        private readonly HttpClient localHttpClient;
+
+        public Tinami()
+            : this(null)
+        {
+        }
 
         public Tinami(HttpClient http)
         {
-            this.http = http;
+            this.localHttpClient = http;
         }
 
         public override async Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
@@ -69,9 +80,9 @@ namespace OpenTween.Thumbnail.Services
 
                 return new ThumbnailInfo
                 {
-                    ImageUrl = url,
-                    ThumbnailUrl = thumbUrlElm.Attribute("url").Value,
-                    TooltipText = descElm == null ? null : descElm.Value,
+                    MediaPageUrl = url,
+                    ThumbnailImageUrl = thumbUrlElm.Attribute("url").Value,
+                    TooltipText = descElm?.Value,
                 };
             }
             catch (HttpRequestException) { }
@@ -83,8 +94,8 @@ namespace OpenTween.Thumbnail.Services
         {
             var query = new Dictionary<string, string>
             {
-                {"api_key", ApplicationSettings.TINAMIApiKey},
-                {"cont_id", contentId},
+                ["api_key"] = ApplicationSettings.TINAMIApiKey,
+                ["cont_id"] = contentId,
             };
 
             var apiUrl = new Uri("http://api.tinami.com/content/info?" + MyCommon.BuildQueryString(query));