static public String Gallery(GallerySection section, GallerySort sort, int page) { return(String.Format(_gallery, Utilities.convertToString(section), Utilities.convertToString(sort), page)); }
/// <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); } }
/// <summary> /// Returns the images in the gallery. /// </summary> /// <param name="section">The gallery section. Default: Hot</param> /// <param name="sort">The order that the gallery should be sorted by. Default: Viral</param> /// <param name="window">The time period that should be used in filtering requests. Default: Day</param> /// <param name="page">The data paging number. Default: null</param> /// <param name="showViral">Show or hide viral images from the 'user' section. Default: true</param> /// <exception cref="ArgumentNullException"> /// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// </exception> /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception> /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception> /// <returns></returns> 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; } }
/// <summary> /// Returns the list of images in the Main gallery in the given section and with the given sort method /// </summary> /// <param name="section">The section to get the images from.</param> /// <param name="sorting">The sorting method to use to sort the returned images. Default is the viral sorting method.</param> /// <param name="page">The page number to return images from. Default is the first page (0).</param> /// <returns>The list of images in the chosen gallery</returns> public async Task <ImgurGalleryImageList> GalleryDetailsAsync(GallerySection section, GallerySort sorting = GallerySort.viral, int page = 0) { string responseString = await GetAnonymousImgurDataAsync(ImgurEndpoints.Gallery(section, sorting, page)); return(await Task.Run(() => JsonConvert.DeserializeObject <ImgurGalleryImageList>(responseString, _defaultSerializerSettings))); }