/// <summary> /// Returns the images in the gallery /// </summary> /// <param name="page">The current page</param> /// <param name="section">The section of the site</param> /// <param name="sort">The sort method</param> /// <param name="window">Change the date range of the request if the section is "top"</param> /// <param name="showVirual">Show or hide viral images from the 'user' section.</param> public async Task <ImgurResponse <IGalleryObject[]> > GetGalleryImagesAsync(int page = 0, GallerySection section = GallerySection.Hot, GallerySort sort = GallerySort.Viral, GalleryWindow window = GalleryWindow.Day, bool showVirual = true) { if (ImgurClient.Authentication == null) { throw new InvalidAuthenticationException("Authentication can not be null. Set it in the main Imgur class."); } var endpoint = String.Format(GalleryUrl, section.ToString().ToLowerInvariant(), sort.ToString().ToLowerInvariant(), window.ToString().ToLowerInvariant(), page, showVirual.ToString().ToLowerInvariant()); return (await Request.SubmitImgurRequestAsync(Request.HttpMethod.Get, endpoint, ImgurClient.Authentication, customParser : ParseGalleryObjectArrayResponse)); }
/// <summary> /// Fetches gallery submissions. /// </summary> /// <param name="section">The section of the gallery to fetch.</param> /// <param name="sort">How to sort the gallery.</param> /// <param name="window">The maximum age of the submissions to fetch.</param> /// <param name="page">What page of the gallery to fetch.</param> /// <param name="showViral">If true, viral pots will be included. If false, viral posts will be excluded.</param> /// <exception cref="ArgumentException">Thrown when arguments are invalid or conflicting.</exception> /// <exception cref="ImgurException">Thrown when Imgur encountered an error.</exception> /// <returns>An array with gallery submissions.</returns> public async Task <ICollection <IGalleryAlbumImageBase> > GetGalleryAsync(GallerySection section = GallerySection.Hot, GallerySortBy sort = GallerySortBy.Viral, GalleryWindow window = GalleryWindow.Day, uint page = 0, bool showViral = true) { if (sort == GallerySortBy.Rising && section != GallerySection.User) { throw new ArgumentException(nameof(sort) + " can only be rising if " + nameof(section) + " is user."); } var sectionStr = section.ToString().ToLower(); var sortStr = sort.ToString().ToLower(); var windowStr = window.ToString().ToLower(); var url = $"gallery/{sectionStr}/{sortStr}/{windowStr}/{page}.json?showViral={showViral}"; using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url)) { var gallery = await SendRequestAsync <IGalleryAlbumImageBase[]>(request); return(gallery); } }