/// <summary> /// View gallery images for a subreddit. /// </summary> /// <param name="subreddit">A valid subreddit name. Example: pics, gaming</param> /// <param name="sort">The order that the gallery should be sorted by. Default: Time</param> /// <param name="window">The time period that should be used in filtering requests. Default: Week</param> /// <param name="page">The data paging number. Default: null</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<IGalleryImage>> GetSubredditGalleryAsync(string subreddit, SubredditGallerySortOrder? sort = SubredditGallerySortOrder.Time, TimeWindow? window = TimeWindow.Week, int? page = null) { if (string.IsNullOrWhiteSpace(subreddit)) throw new ArgumentNullException(nameof(subreddit)); sort = sort ?? SubredditGallerySortOrder.Time; window = window ?? TimeWindow.Week; var sortValue = $"{sort}".ToLower(); var windowValue = $"{window}".ToLower(); var url = $"gallery/r/{subreddit}/{sortValue}/{windowValue}/{page}"; using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url)) { var gallery = await SendRequestAsync<IEnumerable<GalleryImage>>(request).ConfigureAwait(false); return gallery; } }
public async Task <IEnumerable <IGalleryItem> > GetItemsFromSubAsync(string sub, int amount, SubredditGallerySortOrder order, TimeWindow time) { if (this.IsDisabled()) { return(null); } if (string.IsNullOrWhiteSpace(sub)) { throw new ArgumentException("Subreddit missing!", nameof(sub)); } if (amount < 1 || amount > 10) { throw new ArgumentException("Result amount out of range (max 10)", nameof(amount)); } IEnumerable <IGalleryItem> images = await this.gEndpoint.GetSubredditGalleryAsync(sub, order, time).ConfigureAwait(false); return(images.Take(amount)); }