Exemple #1
0
 public static async Task <IApiResult <TwitterStatus> > RetweetAsync(
     [NotNull] this IApiAccessor accessor, long id,
     CancellationToken cancellationToken)
 {
     if (accessor == null)
     {
         throw new ArgumentNullException(nameof(accessor));
     }
     return(await accessor.PostAsync("statuses/retweet/" + id + ".json",
                                     ParameterHelper.CreateEmpty().SetExtended(),
                                     ResultHandlers.ReadAsStatusAsync, cancellationToken).ConfigureAwait(false));
 }
Exemple #2
0
 private static async Task <IApiResult <string> > UploadCoreAsync(
     [NotNull] this IApiAccessor accessor, [NotNull] HttpContent content,
     CancellationToken cancellationToken)
 {
     if (content == null)
     {
         throw new ArgumentNullException(nameof(content));
     }
     return(await accessor.PostAsync(MediaUploadPath, content,
                                     async resp => await resp.ReadAsStringAsync().ConfigureAwait(false),
                                     cancellationToken).ConfigureAwait(false));
 }
Exemple #3
0
 public static async Task <IApiResult <TwitterSavedSearch> > DestroySavedSearchAsync(
     [NotNull] this IApiAccessor accessor, long id,
     CancellationToken cancellationToken)
 {
     if (accessor == null)
     {
         throw new ArgumentNullException(nameof(accessor));
     }
     return(await accessor.PostAsync("saved_searches/destroy/" + id + ".json",
                                     new Dictionary <string, object>(), ResultHandlers.ReadAsSavedSearchAsync,
                                     cancellationToken)
            .ConfigureAwait(false));
 }
Exemple #4
0
 public static async Task <IApiResult <TwitterUser> > ReportSpamAsync(
     [NotNull] this IApiAccessor accessor, [NotNull] UserParameter targetUser,
     CancellationToken cancellationToken)
 {
     if (accessor == null)
     {
         throw new ArgumentNullException(nameof(accessor));
     }
     if (targetUser == null)
     {
         throw new ArgumentNullException(nameof(targetUser));
     }
     return(await accessor.PostAsync("users/report_spam.json", targetUser.ToDictionary(),
                                     ResultHandlers.ReadAsUserAsync, cancellationToken).ConfigureAwait(false));
 }
Exemple #5
0
 private static async Task <IApiResult <TwitterUploadedMedia> > UploadMediaCoreAsync(
     [NotNull] this IApiAccessor accessor, [NotNull] HttpContent content,
     CancellationToken cancellationToken)
 {
     if (content == null)
     {
         throw new ArgumentNullException(nameof(content));
     }
     return(await accessor.PostAsync(MediaUploadPath, content,
                                     async resp =>
     {
         var json = await resp.ReadAsStringAsync().ConfigureAwait(false);
         return new TwitterUploadedMedia(MeteorJson.Parse(json));
     }, cancellationToken).ConfigureAwait(false));
 }
Exemple #6
0
 public static async Task <IApiResult <TwitterStatus> > UpdateAsync(
     [NotNull] this IApiAccessor accessor, [NotNull] StatusParameter status,
     CancellationToken cancellationToken)
 {
     if (accessor == null)
     {
         throw new ArgumentNullException(nameof(accessor));
     }
     if (status == null)
     {
         throw new ArgumentNullException(nameof(status));
     }
     return(await accessor.PostAsync("statuses/update.json", status.ToDictionary().SetExtended(),
                                     ResultHandlers.ReadAsStatusAsync, cancellationToken).ConfigureAwait(false));
 }
        public static async Task <IApiResult <TwitterStatus> > DestroyDirectMessageAsync(
            [NotNull] this IApiAccessor accessor, long id,
            CancellationToken cancellationToken)
        {
            if (accessor == null)
            {
                throw new ArgumentNullException(nameof(accessor));
            }
            var param = new Dictionary <string, object>
            {
                { "id", id }
            }.SetExtended();

            return(await accessor.PostAsync("direct_messages/destroy.json", param,
                                            ResultHandlers.ReadAsStatusAsync, cancellationToken).ConfigureAwait(false));
        }
Exemple #8
0
        public static async Task <IApiResult <TwitterUser> > UpdateMuteAsync(
            [NotNull] this IApiAccessor accessor,
            [NotNull] UserParameter targetUser, bool mute, CancellationToken cancellationToken)
        {
            if (accessor == null)
            {
                throw new ArgumentNullException(nameof(accessor));
            }
            if (targetUser == null)
            {
                throw new ArgumentNullException(nameof(targetUser));
            }
            var endpoint = mute ? "mutes/users/create" : "mutes/users/destroy";

            return(await accessor.PostAsync(endpoint, targetUser.ToDictionary(),
                                            ResultHandlers.ReadAsUserAsync, cancellationToken).ConfigureAwait(false));
        }
Exemple #9
0
        public static async Task <IApiResult <TwitterSavedSearch> > SaveSearchAsync(
            [NotNull] this IApiAccessor accessor, [NotNull] string query,
            CancellationToken cancellationToken)
        {
            if (accessor == null)
            {
                throw new ArgumentNullException(nameof(accessor));
            }
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }
            var param = new Dictionary <string, object>
            {
                { "query", query }
            };

            return(await accessor.PostAsync("saved_searches/create.json", param,
                                            ResultHandlers.ReadAsSavedSearchAsync, cancellationToken).ConfigureAwait(false));
        }
Exemple #10
0
        public static async Task <IApiResult <TwitterUser> > UpdateProfileImageAsync(
            [NotNull] this IApiAccessor accessor,
            [NotNull] byte[] image, CancellationToken cancellationToken)
        {
            if (accessor == null)
            {
                throw new ArgumentNullException(nameof(accessor));
            }
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            var content = new MultipartFormDataContent
            {
                { new StringContent("true"), "skip_status" },
                { new ByteArrayContent(image), "image", "image.png" }
            };

            return(await accessor.PostAsync("account/update_profile_image.json",
                                            content, ResultHandlers.ReadAsUserAsync, cancellationToken).ConfigureAwait(false));
        }
Exemple #11
0
        public static async Task <IApiResult <TwitterUser> > UpdateProfileAsync(
            [NotNull] this IApiAccessor accessor, [CanBeNull] string name, [CanBeNull] string url,
            [CanBeNull] string location, [CanBeNull] string description,
            CancellationToken cancellationToken)
        {
            if (accessor == null)
            {
                throw new ArgumentNullException(nameof(accessor));
            }
            var param = new Dictionary <string, object>
            {
                { "name", name },
                { "url", url },
                { "location", location },
                { "description", description },
                { "skip_status", true },
            };

            return(await accessor.PostAsync("account/update_profile.json",
                                            param, ResultHandlers.ReadAsUserAsync, cancellationToken).ConfigureAwait(false));
        }
Exemple #12
0
        public static async Task <IApiResult <TwitterFriendship> > UpdateFriendshipAsync(
            [NotNull] this IApiAccessor accessor,
            [NotNull] UserParameter screenName, bool?enableDeviceNotifications, bool?showRetweet,
            CancellationToken cancellationToken)
        {
            if (accessor == null)
            {
                throw new ArgumentNullException(nameof(accessor));
            }
            if (screenName == null)
            {
                throw new ArgumentNullException(nameof(screenName));
            }

            var param = new Dictionary <string, object>
            {
                { "device", enableDeviceNotifications },
                { "retweets", showRetweet },
            }.ApplyParameter(screenName);

            return(await accessor.PostAsync("friendships/update.json", param,
                                            ResultHandlers.ReadAsFriendshipAsync, cancellationToken).ConfigureAwait(false));
        }
Exemple #13
0
        public static async Task <IApiResult <TwitterStatus> > SendDirectMessageAsync(
            [NotNull] this IApiAccessor accessor, [NotNull] UserParameter recipient, [NotNull] string text,
            CancellationToken cancellationToken)
        {
            if (accessor == null)
            {
                throw new ArgumentNullException(nameof(accessor));
            }
            if (recipient == null)
            {
                throw new ArgumentNullException(nameof(recipient));
            }
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }
            var param = new Dictionary <string, object>
            {
                { "text", text }
            }.ApplyParameter(recipient).SetExtended();

            return(await accessor.PostAsync("direct_messages/new.json", param,
                                            ResultHandlers.ReadAsStatusAsync, cancellationToken).ConfigureAwait(false));
        }