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

GetRandomGalleryAsync() public method

Returns a random set of gallery images.
/// 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 GetRandomGalleryAsync ( int page = null ) : Task>
page int A page of random gallery images, from 0-50. Pages are regenerated every hour.
return Task>
        public async Task<IEnumerable<IGalleryItem>> GetRandomGalleryAsync(int? page = null)
        {
            var url = $"gallery/random/random/{page}";

            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 GetRandomGalleryAsync_WithPage_Any()
        {
            var mockUrl = "https://api.imgur.com/3/gallery/random/random/8";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.GetRandomGallery)
            };

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

            Assert.True(gallery.Any());
        }