예제 #1
0
        /// <summary>
        ///     Search the gallery with a given query string.
        /// </summary>
        /// <param name="qAll">Search for all of these words (and).</param>
        /// <param name="qAny">Search for any of these words (or).</param>
        /// <param name="qExactly">Search for exactly this word or phrase.</param>
        /// <param name="qNot">Exclude results matching this word or phrase.</param>
        /// <param name="fileType">Show results for a specific file type.</param>
        /// <param name="imageSize">Show results for a specific image size.</param>
        /// <param name="sort">The order that the gallery should be sorted by. Default: Time</param>
        /// <param name="window">The time period that should be used in filtering requests. Default: Day</param>
        /// <param name="page">The data paging number. Default: null</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <IEnumerable <IGalleryItem> > SearchGalleryAdvancedAsync(
            string qAll            = null, string qAny = null,
            string qExactly        = null, string qNot = null,
            ImageFileType?fileType = null, ImageSize?imageSize = null,
            GallerySortOrder?sort  = GallerySortOrder.Time,
            TimeWindow?window      = TimeWindow.All, int?page = null)
        {
            if (string.IsNullOrWhiteSpace(qAll) &&
                string.IsNullOrWhiteSpace(qAny) &&
                string.IsNullOrWhiteSpace(qExactly) &&
                string.IsNullOrWhiteSpace(qNot))
            {
                throw new ArgumentNullException(null,
                                                "At least one search parameter must be provided (All | Any | Exactly | Not).");
            }

            sort   = sort ?? GallerySortOrder.Time;
            window = window ?? TimeWindow.All;

            var sortValue   = $"{sort}".ToLower();
            var windowValue = $"{window}".ToLower();

            var url = $"gallery/search/{sortValue}/{windowValue}/{page}";

            url = GalleryRequestBuilder.SearchGalleryAdvancedRequest(url, qAll, qAny, qExactly, qNot, fileType,
                                                                     imageSize);

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, url))
            {
                var searchResults = await SendRequestAsync <IEnumerable <GalleryItem> >(request).ConfigureAwait(false);

                return(searchResults);
            }
        }
예제 #2
0
        /// <summary>
        ///     Search the gallery with a given query string.
        /// </summary>
        /// <param name="query">
        ///     Query string to search by. This parameter also supports boolean operators (AND, OR, NOT) and
        ///     indices (tag: user: title: ext: subreddit: album: meme:). An example compound query would be 'title: cats AND dogs
        ///     ext: gif'
        /// </param>
        /// <param name="sort">The order that the gallery should be sorted by. Default: Time</param>
        /// <param name="window">The time period that should be used in filtering requests. Default: Day</param>
        /// <param name="page">The data paging number. Default: null</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <IEnumerable <IGalleryItem> > SearchGalleryAsync(string query,
                                                                           GallerySortOrder?sort = GallerySortOrder.Time,
                                                                           TimeWindow?window     = TimeWindow.All, int?page = null)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                throw new ArgumentNullException(nameof(query));
            }

            sort   = sort ?? GallerySortOrder.Time;
            window = window ?? TimeWindow.All;

            var sortValue   = $"{sort}".ToLower();
            var windowValue = $"{window}".ToLower();

            var url = $"gallery/search/{sortValue}/{windowValue}/{page}";

            url = GalleryRequestBuilder.SearchGalleryRequest(url, query);

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, url))
            {
                var searchResults = await SendRequestAsync <IEnumerable <GalleryItem> >(request).ConfigureAwait(false);

                return(searchResults);
            }
        }
예제 #3
0
        /// <summary>
        ///     Deletes an Image. You are required to be logged in as the user whom created the image.
        ///     OAuth authentication required.
        /// </summary>
        /// <param name="imageId">The image id.</param>
        /// <param name="username">The user account. Default: me</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <bool> DeleteImageAsync(string imageId, string username = "******")
        {
            if (string.IsNullOrWhiteSpace(imageId))
            {
                throw new ArgumentNullException(nameof(imageId));
            }

            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentNullException(nameof(username));
            }

            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            var url = $"account/{username}/image/{imageId}";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Delete, url))
            {
                var deleted = await SendRequestAsync <bool>(request).ConfigureAwait(false);

                return(deleted);
            }
        }
예제 #4
0
        /// <summary>
        ///     Return information about a specific image.
        /// </summary>
        /// <param name="imageId">The image's id.</param>
        /// <param name="username">The user account. Default: me</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <IImage> GetImageAsync(string imageId, string username = "******")
        {
            if (string.IsNullOrWhiteSpace(imageId))
            {
                throw new ArgumentNullException(nameof(imageId));
            }

            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentNullException(nameof(username));
            }

            if (username.Equals("me", StringComparison.OrdinalIgnoreCase) &&
                ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            var url = $"account/{username}/image/{imageId}";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, url))
            {
                var image = await SendRequestAsync <Image>(request).ConfigureAwait(false);

                return(image);
            }
        }
예제 #5
0
        /// <summary>
        ///     Get the list of default topics.
        /// </summary>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <IEnumerable <ITopic> > GetDefaultTopicsAsync()
        {
            var url = "topics/defaults";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, url))
            {
                var topics = await SendRequestAsync <IEnumerable <Topic> >(request).ConfigureAwait(false);

                return(topics);
            }
        }
예제 #6
0
        /// <summary>
        ///     Deletes an image. For an anonymous image, {id} must be the image's deletehash.
        ///     If the image belongs to your account then passing the ID of the image is sufficient.
        /// </summary>
        /// <param name="imageId">The image id.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        private async Task <bool> DeleteImageInternalAsync(string imageId)
        {
            var url = $"image/{imageId}";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Delete, url))
            {
                var deleted = await SendRequestAsync <bool>(request).ConfigureAwait(false);

                return(deleted);
            }
        }
예제 #7
0
        /// <summary>
        ///     Returns a random set of gallery images.
        /// </summary>
        /// <param name="page">A page of random gallery images, from 0-50. Pages are regenerated every hour.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <IEnumerable <IGalleryItem> > GetRandomGalleryAsync(int?page = null)
        {
            var url = $"gallery/random/random/{page}";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, url))
            {
                var gallery = await SendRequestAsync <IEnumerable <GalleryItem> >(request).ConfigureAwait(false);

                return(gallery);
            }
        }
예제 #8
0
        /// <summary>
        ///     Get the comment with all of the replies for the comment.
        /// </summary>
        /// <param name="commentId">The comment id.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <IComment> GetRepliesAsync(int commentId)
        {
            var url = $"comment/{commentId}/replies";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, url))
            {
                var comment = await SendRequestAsync <Comment>(request).ConfigureAwait(false);

                return(comment);
            }
        }
예제 #9
0
        /// <summary>
        ///     Favorite an image with the given ID. OAuth authentication required.
        /// </summary>
        /// <param name="imageId">The image id.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        private async Task <bool> FavoriteImageInternalAsync(string imageId)
        {
            var url = $"image/{imageId}/favorite";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Post, url))
            {
                var imgurResult = await SendRequestAsync <string>(request).ConfigureAwait(false);

                return(imgurResult.Equals("favorited", StringComparison.OrdinalIgnoreCase));
            }
        }
예제 #10
0
        /// <summary>
        ///     Get information about an image.
        /// </summary>
        /// <param name="imageId">The image id.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        private async Task <IImage> GetImageInternalAsync(string imageId)
        {
            var url = $"image/{imageId}";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, url))
            {
                var image = await SendRequestAsync <Image>(request).ConfigureAwait(false);

                return(image);
            }
        }
예제 #11
0
        /// <summary>
        ///     Get the list of default memes.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <IEnumerable <IImage> > GetDefaultMemesAsync()
        {
            var url = "memegen/defaults";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, url))
            {
                var images = await SendRequestAsync <IEnumerable <Image> >(request).ConfigureAwait(false);

                return(images);
            }
        }
예제 #12
0
        public void ReportItemRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new AccountRequestBuilder();

            var exception = Record.Exception(() => RequestBuilderBase.ReportItemRequest(null, ReportReason.Abusive));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "url");
        }
예제 #13
0
        public void CreateRequest_WithHttpMethodNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new AccountRequestBuilder();

            var exception = Record.Exception(() => RequestBuilderBase.CreateRequest(null, null));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "httpMethod");
        }
예제 #14
0
        /// <summary>
        ///     Gets remaining credits for the application.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <returns></returns>
        public IRateLimit GetRateLimit()
        {
            IRateLimit limit;

            var url = "credits";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, url))
            {
                limit = SendRequestAsync <RateLimit>(request).Data;
            }

            return(limit);
        }
예제 #15
0
        public async Task ReportItemRequest_Equal()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CommentRequestBuilder();

            var mockUrl = $"{client.EndpointUrl}comment/XysioD/report";
            var request = RequestBuilderBase.ReportItemRequest(mockUrl, ReportReason.Abusive);

            Assert.NotNull(request);
            var expected = "reason=3";

            Assert.Equal(expected, await request.Content.ReadAsStringAsync().ConfigureAwait(false));
            Assert.Equal("https://api.imgur.com/3/comment/XysioD/report", request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Post, request.Method);
        }
예제 #16
0
        /// <summary>
        ///     Returns the account settings. OAuth authentication required.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <IAccountSettings> GetAccountSettingsAsync()
        {
            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            const string url = "account/me/settings";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, url))
            {
                var settings = await SendRequestAsync <AccountSettings>(request).ConfigureAwait(false);

                return(settings);
            }
        }
예제 #17
0
        /// <summary>
        ///     Deletes an image. For an anonymous image, {id} must be the image's deletehash.
        ///     If the image belongs to your account then passing the ID of the image is sufficient.
        /// </summary>
        /// <param name="imageId">The image id.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <bool> DeleteImageAsync(string imageId)
        {
            if (string.IsNullOrWhiteSpace(imageId))
            {
                throw new ArgumentNullException(nameof(imageId));
            }

            var url = $"image/{imageId}";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Delete, url))
            {
                var deleted = await SendRequestAsync <bool>(request).ConfigureAwait(false);

                return(deleted);
            }
        }
예제 #18
0
        /// <summary>
        ///     List all of the IDs for the comments on an item.
        /// </summary>
        /// <param name="galleryItemId">The gallery item id.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <IEnumerable <int> > GetGalleryItemCommentIdsAsync(string galleryItemId)
        {
            if (string.IsNullOrWhiteSpace(galleryItemId))
            {
                throw new ArgumentNullException(nameof(galleryItemId));
            }

            var url = $"gallery/{galleryItemId}/comments/ids";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, url))
            {
                var commentIds = await SendRequestAsync <IEnumerable <int> >(request).ConfigureAwait(false);

                return(commentIds);
            }
        }
예제 #19
0
        /// <summary>
        ///     Report a comment for being inappropriate.
        ///     OAuth authentication required.
        /// </summary>
        /// <param name="commentId">The comment id.</param>
        /// <param name="reason">The reason why the comment is inappropriate.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <bool> ReportCommentAsync(int commentId, ReportReason reason)
        {
            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            var url = $"comment/{commentId}/report";

            using (var request = RequestBuilderBase.ReportItemRequest(url, reason))
            {
                var reported = await SendRequestAsync <bool?>(request).ConfigureAwait(false);

                return(reported ?? true);
            }
        }
예제 #20
0
        /// <summary>
        ///     Delete a comment by the given id.
        ///     OAuth authentication required.
        /// </summary>
        /// <param name="commentId">The comment id.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <bool> DeleteCommentAsync(int commentId)
        {
            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            var url = $"comment/{commentId}";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Delete, url))
            {
                var deleted = await SendRequestAsync <bool>(request).ConfigureAwait(false);

                return(deleted);
            }
        }
예제 #21
0
        /// <summary>
        ///     Return all of the images in the album.
        /// </summary>
        /// <param name="albumId">The album id.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <IEnumerable <IImage> > GetAlbumImagesAsync(string albumId)
        {
            if (string.IsNullOrWhiteSpace(albumId))
            {
                throw new ArgumentNullException(nameof(albumId));
            }

            var url = $"album/{albumId}/images";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, url))
            {
                var images = await SendRequestAsync <IEnumerable <Image> >(request).ConfigureAwait(false);

                return(images);
            }
        }
예제 #22
0
        /// <summary>
        ///     Get information about a specific album.
        /// </summary>
        /// <param name="albumId">The album id.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <IAlbum> GetAlbumAsync(string albumId)
        {
            if (string.IsNullOrWhiteSpace(albumId))
            {
                throw new ArgumentNullException(nameof(albumId));
            }

            var url = $"album/{albumId}";

            using (var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, url))
            {
                var album = await SendRequestAsync <Album>(request).ConfigureAwait(false);

                return(album);
            }
        }