OSDN Git Service

HttpTwitter.GetListMembersメソッドをTwitterApiクラスに置き換え
[opentween/open-tween.git] / OpenTween / Api / TwitterApi.cs
index ff95b24..c8d1058 100644 (file)
@@ -21,6 +21,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading;
@@ -35,6 +36,8 @@ namespace OpenTween.Api
         public long CurrentUserId { get; private set; }
         public string CurrentScreenName { get; private set; }
 
+        public IApiConnection Connection => this.apiConnection;
+
         internal IApiConnection apiConnection;
 
         public void Initialize(string accessToken, string accessSecret, long userId, string screenName)
@@ -161,6 +164,79 @@ namespace OpenTween.Api
             return this.apiConnection.PostLazyAsync<TwitterStatus>(endpoint, param);
         }
 
+        public Task<TwitterLists> ListsOwnerships(string screenName, long? cursor = null)
+        {
+            var endpoint = new Uri("lists/ownerships.json", UriKind.Relative);
+            var param = new Dictionary<string, string>
+            {
+                ["screen_name"] = screenName,
+            };
+
+            if (cursor != null)
+                param["cursor"] = cursor.ToString();
+
+            return this.apiConnection.GetAsync<TwitterLists>(endpoint, param, "/lists/ownerships");
+        }
+
+        public Task<TwitterLists> ListsSubscriptions(string screenName, long? cursor = null)
+        {
+            var endpoint = new Uri("lists/subscriptions.json", UriKind.Relative);
+            var param = new Dictionary<string, string>
+            {
+                ["screen_name"] = screenName,
+            };
+
+            if (cursor != null)
+                param["cursor"] = cursor.ToString();
+
+            return this.apiConnection.GetAsync<TwitterLists>(endpoint, param, "/lists/subscriptions");
+        }
+
+        public Task<LazyJson<TwitterList>> ListsCreate(string name, string description = null, bool? @private = null)
+        {
+            var endpoint = new Uri("lists/create.json", UriKind.Relative);
+            var param = new Dictionary<string, string>
+            {
+                ["name"] = name,
+            };
+
+            if (description != null)
+                param["description"] = description;
+            if (@private != null)
+                param["mode"] = @private.Value ? "private" : "public";
+
+            return this.apiConnection.PostLazyAsync<TwitterList>(endpoint, param);
+        }
+
+        public Task<LazyJson<TwitterList>> ListsUpdate(long listId, string name = null, string description = null, bool? @private = null)
+        {
+            var endpoint = new Uri("lists/update.json", UriKind.Relative);
+            var param = new Dictionary<string, string>
+            {
+                ["list_id"] = listId.ToString(),
+            };
+
+            if (name != null)
+                param["name"] = name;
+            if (description != null)
+                param["description"] = description;
+            if (@private != null)
+                param["mode"] = @private.Value ? "private" : "public";
+
+            return this.apiConnection.PostLazyAsync<TwitterList>(endpoint, param);
+        }
+
+        public Task<LazyJson<TwitterList>> ListsDestroy(long listId)
+        {
+            var endpoint = new Uri("lists/destroy.json", UriKind.Relative);
+            var param = new Dictionary<string, string>
+            {
+                ["list_id"] = listId.ToString(),
+            };
+
+            return this.apiConnection.PostLazyAsync<TwitterList>(endpoint, param);
+        }
+
         public Task<TwitterStatus[]> ListsStatuses(long listId, int? count = null, long? maxId = null, long? sinceId = null, bool? includeRTs = null)
         {
             var endpoint = new Uri("lists/statuses.json", UriKind.Relative);
@@ -183,6 +259,22 @@ namespace OpenTween.Api
             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);
@@ -431,6 +523,13 @@ namespace OpenTween.Api
             return this.apiConnection.PostLazyAsync<TwitterUser>(endpoint, param, paramMedia);
         }
 
+        public Task<TwitterRateLimits> ApplicationRateLimitStatus()
+        {
+            var endpoint = new Uri("application/rate_limit_status.json", UriKind.Relative);
+
+            return this.apiConnection.GetAsync<TwitterRateLimits>(endpoint, null, "/application/rate_limit_status");
+        }
+
         public Task<TwitterConfiguration> Configuration()
         {
             var endpoint = new Uri("help/configuration.json", UriKind.Relative);
@@ -449,6 +548,24 @@ namespace OpenTween.Api
             return this.apiConnection.PostLazyAsync<TwitterUploadMediaResult>(endpoint, null, paramMedia);
         }
 
+        public Task<Stream> UserStreams(string replies = null, string track = null)
+        {
+            var endpoint = new Uri("https://userstream.twitter.com/1.1/user.json");
+            var param = new Dictionary<string, string>();
+
+            if (replies != null)
+                param["replies"] = replies;
+            if (track != null)
+                param["track"] = track;
+
+            return this.apiConnection.GetStreamAsync(endpoint, param);
+        }
+
+        public OAuthEchoHandler CreateOAuthEchoHandler(Uri authServiceProvider, Uri realm = null)
+        {
+            return ((TwitterApiConnection)this.apiConnection).CreateOAuthEchoHandler(authServiceProvider, realm);
+        }
+
         public void Dispose()
         {
             this.apiConnection?.Dispose();