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

SearchGalleryAsync() 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 SearchGalleryAsync ( string query, GallerySortOrder sort = GallerySortOrder.Time, TimeWindow window = TimeWindow.All, int page = null ) : Task>
query string /// 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' ///
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>> 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 = RequestBuilder.SearchGalleryRequest(url, query);

            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 SearchGalleryAsync_WithQueryNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client);

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