using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
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)
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[]> StatusesUserTimeline(string screenName, int? count = null, long? maxId = null, long? sinceId = null)
+ {
+ var endpoint = new Uri("statuses/user_timeline.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["screen_name"] = screenName,
+ ["include_rts"] = "true",
+ ["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/user_timeline");
+ }
+
public Task<TwitterStatus> StatusesShow(long statusId)
{
var endpoint = new Uri("statuses/show.json", UriKind.Relative);
{
["id"] = statusId.ToString(),
["include_entities"] = "true",
+ ["include_ext_alt_text"] = "true",
};
return this.apiConnection.GetAsync<TwitterStatus>(endpoint, param, "/statuses/show/:id");
}
+ public Task<LazyJson<TwitterStatus>> StatusesUpdate(string status, long? replyToId, IReadOnlyList<long> mediaIds)
+ {
+ var endpoint = new Uri("statuses/update.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["status"] = status,
+ ["include_entities"] = "true",
+ ["include_ext_alt_text"] = "true",
+ };
+
+ if (replyToId != null)
+ param["in_reply_to_status_id"] = replyToId.ToString();
+ if (mediaIds != null && mediaIds.Count > 0)
+ param.Add("media_ids", string.Join(",", mediaIds));
+
+ return this.apiConnection.PostLazyAsync<TwitterStatus>(endpoint, param);
+ }
+
public Task<LazyJson<TwitterStatus>> StatusesDestroy(long statusId)
{
var endpoint = new Uri("statuses/destroy.json", UriKind.Relative);
return this.apiConnection.PostLazyAsync<TwitterStatus>(endpoint, param);
}
+ public Task<LazyJson<TwitterStatus>> StatusesRetweet(long statusId)
+ {
+ var endpoint = new Uri("statuses/retweet.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["id"] = statusId.ToString(),
+ ["include_entities"] = "true",
+ ["include_ext_alt_text"] = "true",
+ };
+
+ 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);
+ var param = new Dictionary<string, string>
+ {
+ ["list_id"] = listId.ToString(),
+ ["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();
+ if (includeRTs != null)
+ param["include_rts"] = includeRTs.Value ? "true" : "false";
+
+ 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);
+ var param = new Dictionary<string, string>
+ {
+ ["full_text"] = "true",
+ ["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<TwitterDirectMessage[]>(endpoint, param, "/direct_messages");
+ }
+
+ public Task<TwitterDirectMessage[]> DirectMessagesSent(int? count = null, long? maxId = null, long? sinceId = null)
+ {
+ var endpoint = new Uri("direct_messages/sent.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["full_text"] = "true",
+ ["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<TwitterDirectMessage[]>(endpoint, param, "/direct_messages/sent");
+ }
+
+ public Task<LazyJson<TwitterDirectMessage>> DirectMessagesNew(string status, string sendTo)
+ {
+ var endpoint = new Uri("direct_messages/new.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["text"] = status,
+ ["screen_name"] = sendTo,
+ };
+
+ return this.apiConnection.PostLazyAsync<TwitterDirectMessage>(endpoint, param);
+ }
+
public Task<LazyJson<TwitterDirectMessage>> DirectMessagesDestroy(long statusId)
{
var endpoint = new Uri("direct_messages/destroy.json", UriKind.Relative);
{
["screen_name"] = screenName,
["include_entities"] = "true",
+ ["include_ext_alt_text"] = "true",
};
return this.apiConnection.GetAsync<TwitterUser>(endpoint, param, "/users/show/:id");
return this.apiConnection.PostLazyAsync<TwitterFriendship>(endpoint, param);
}
+ public Task<long[]> NoRetweetIds(long? cursor = null)
+ {
+ var endpoint = new Uri("friendships/no_retweets/ids.json", UriKind.Relative);
+
+ return this.apiConnection.GetAsync<long[]>(endpoint, null, "/friendships/no_retweets/ids");
+ }
+
+ public Task<TwitterIds> FollowersIds(long? cursor = null)
+ {
+ var endpoint = new Uri("followers/ids.json", UriKind.Relative);
+ var param = new Dictionary<string, string>();
+
+ if (cursor != null)
+ param["cursor"] = cursor.ToString();
+
+ return this.apiConnection.GetAsync<TwitterIds>(endpoint, param, "/followers/ids");
+ }
+
+ public Task<TwitterIds> MutesUsersIds(long? cursor = null)
+ {
+ var endpoint = new Uri("mutes/users/ids.json", UriKind.Relative);
+ var param = new Dictionary<string, string>();
+
+ if (cursor != null)
+ param["cursor"] = cursor.ToString();
+
+ return this.apiConnection.GetAsync<TwitterIds>(endpoint, param, "/mutes/users/ids");
+ }
+
+ public Task<TwitterIds> BlocksIds(long? cursor = null)
+ {
+ var endpoint = new Uri("blocks/ids.json", UriKind.Relative);
+ var param = new Dictionary<string, string>();
+
+ if (cursor != null)
+ param["cursor"] = cursor.ToString();
+
+ return this.apiConnection.GetAsync<TwitterIds>(endpoint, param, "/blocks/ids");
+ }
+
public Task<LazyJson<TwitterUser>> BlocksCreate(string screenName)
{
var endpoint = new Uri("blocks/create.json", UriKind.Relative);
var param = new Dictionary<string, string>
{
["include_entities"] = "true",
+ ["include_ext_alt_text"] = "true",
};
if (name != null)
var param = new Dictionary<string, string>
{
["include_entities"] = "true",
+ ["include_ext_alt_text"] = "true",
};
var paramMedia = new Dictionary<string, IMediaItem>
{
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);
+
+ 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");
+ var paramMedia = new Dictionary<string, IMediaItem>
+ {
+ ["media"] = media,
+ };
+
+ 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();