Imgur.API.Endpoints.Impl.GalleryEndpoint.SearchGalleryAdvancedAsync C# (CSharp) Method

SearchGalleryAdvancedAsync() public method

Search the gallery with a given query string.
/// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// Thrown when an error is found in a response from an Imgur endpoint. Thrown when an error is found in a response from a Mashape endpoint.
public 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 ) : Task>
qAll string Search for all of these words (and).
qAny string Search for any of these words (or).
qExactly string Search for exactly this word or phrase.
qNot string Exclude results matching this word or phrase.
fileType ImageFileType Show results for a specific file type.
imageSize ImageSize Show results for a specific image size.
sort GallerySortOrder The order that the gallery should be sorted by. Default: Time
window TimeWindow The time period that should be used in filtering requests. Default: Day
page int The data paging number. Default: null
return Task>
        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 = RequestBuilder.SearchGalleryAdvancedRequest(url, qAll, qAny, qExactly, qNot, fileType,
                imageSize);

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

Usage Example

コード例 #1
0
        public async Task SearchGalleryAdvancedAsync_WithQueriesNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client);

            var exception =
                await
                    Record.ExceptionAsync(
                        async () => await endpoint.SearchGalleryAdvancedAsync().ConfigureAwait(false))
                        .ConfigureAwait(false);
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);
        }
All Usage Examples Of Imgur.API.Endpoints.Impl.GalleryEndpoint::SearchGalleryAdvancedAsync