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

GetGalleryAsync() public method

Returns the images in the gallery.
/// 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 GetGalleryAsync ( GallerySection section = GallerySection.Hot, GallerySortOrder sort = GallerySortOrder.Viral, TimeWindow window = TimeWindow.Day, int page = null, bool showViral = true ) : Task>
section GallerySection The gallery section. Default: Hot
sort GallerySortOrder The order that the gallery should be sorted by. Default: Viral
window TimeWindow The time period that should be used in filtering requests. Default: Day
page int The data paging number. Default: null
showViral bool Show or hide viral images from the 'user' section. Default: true
return Task>
        public async Task<IEnumerable<IGalleryItem>> GetGalleryAsync(GallerySection? section = GallerySection.Hot,
            GallerySortOrder? sort = GallerySortOrder.Viral, TimeWindow? window = TimeWindow.Day, int? page = null,
            bool? showViral = true)
        {
            section = section ?? GallerySection.Hot;
            sort = sort ?? GallerySortOrder.Viral;
            window = window ?? TimeWindow.Week;
            showViral = showViral ?? true;

            var sectionValue = $"{section}".ToLower();
            var sortValue = $"{sort}".ToLower();
            var windowValue = $"{window}".ToLower();
            var showViralValue = $"{showViral}".ToLower();

            var url = $"gallery/{sectionValue}/{sortValue}/{windowValue}/{page}?showViral={showViralValue}";

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

Usage Example

コード例 #1
0
        public async Task GetGalleryAsync_DefaultParameters_Any()
        {
            var mockUrl = "https://api.imgur.com/3/gallery/hot/viral/day/?showViral=true";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.GetGallery)
            };

            var client = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new GalleryEndpoint(client,
                new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var gallery = await endpoint.GetGalleryAsync().ConfigureAwait(false);

            Assert.True(gallery.Any());
        }
All Usage Examples Of Imgur.API.Endpoints.Impl.GalleryEndpoint::GetGalleryAsync