コード例 #1
0
        /// <summary>
        /// View images for memes subgallery.
        /// </summary>
        /// <param name="sort">How to sort the results.</param>
        /// <param name="window">The maximum age of the items in the result.</param>
        /// <param name="page">The page of the result.</param>
        /// <exception cref="ArgumentNullException">Thrown when query was null or empty.</exception>
		/// <exception cref="ArgumentException">Thrown when sort was set to GallerySortBy.Rising.</exception>
        /// <exception cref="ImgurException">Thrown when Imgur encounters an error.</exception>
        /// <returns></returns>
        public async Task<ICollection<IGalleryMeme>> GetMemesSubGalleryAsync(GallerySortBy sort = GallerySortBy.Viral, GalleryWindow window = GalleryWindow.Week, uint page = 0)
        {
            var sortStr = sort.ToString().ToLower();
            var windowStr = window.ToString().ToLower();
            var url = $"g/memes/{sort}/{window}/{page}";

            using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url))
            {
                var images = await SendRequestAsync<IGalleryMeme[]>(request);
                return images;
            }
        }
コード例 #2
0
        /// <summary>
        /// View images for memes subgallery.
        /// </summary>
        /// <param name="sort">How to sort the results.</param>
        /// <param name="window">The maximum age of the items in the result.</param>
        /// <param name="page">The page of the result.</param>
        /// <exception cref="ArgumentNullException">Thrown when query was null or empty.</exception>
        /// <exception cref="ArgumentException">Thrown when sort was set to GallerySortBy.Rising.</exception>
        /// <exception cref="ImgurException">Thrown when Imgur encounters an error.</exception>
        /// <returns></returns>
        public async Task <ICollection <IGalleryMeme> > GetMemesSubGalleryAsync(GallerySortBy sort = GallerySortBy.Viral, GalleryWindow window = GalleryWindow.Week, uint page = 0)
        {
            var sortStr   = sort.ToString().ToLower();
            var windowStr = window.ToString().ToLower();
            var url       = $"g/memes/{sort}/{window}/{page}";

            using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url))
            {
                var images = await SendRequestAsync <IGalleryMeme[]>(request);

                return(images);
            }
        }
コード例 #3
0
        /// <summary>
        /// View images for current user's custom gallery.
        /// </summary>
        /// <param name="sort"></param>
        /// <param name="window"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public async Task<CustomGallery> GetCustomGalleryAsync(GallerySortBy sort = GallerySortBy.Viral, GalleryWindow window = GalleryWindow.Week, uint page = 0)
        {
            if (sort == GallerySortBy.Rising)
                throw new ArgumentException("Cannot sort custom gallery by rising.");

            var sortStr = sort.ToString().ToLower();
            var windowStr = window.ToString().ToLower();
            var url = $"g/custom/{sortStr}/{windowStr}/{page}";

            using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url))
            {
                var customGallery = await SendRequestAsync<CustomGallery>(request);
                return customGallery;
            }
        }
コード例 #4
0
        /// <summary>
        /// View images for current user's custom gallery.
        /// </summary>
        /// <param name="sort"></param>
        /// <param name="window"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public async Task <CustomGallery> GetCustomGalleryAsync(GallerySortBy sort = GallerySortBy.Viral, GalleryWindow window = GalleryWindow.Week, uint page = 0)
        {
            if (sort == GallerySortBy.Rising)
            {
                throw new ArgumentException("Cannot sort custom gallery by rising.");
            }

            var sortStr   = sort.ToString().ToLower();
            var windowStr = window.ToString().ToLower();
            var url       = $"g/custom/{sortStr}/{windowStr}/{page}";

            using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url))
            {
                var customGallery = await SendRequestAsync <CustomGallery>(request);

                return(customGallery);
            }
        }
コード例 #5
0
        /// <summary>
        ///     View images for a gallery tag
        /// </summary>
        /// <param name="tagname">The name of the tag to fetch items for.</param>
        /// <param name="sort">How to sort the items.</param>
        /// <param name="window">The maximum age of the items.</param>
        /// <param name="page">The page to fetch.</param>
        /// <exception cref="ArgumentNullException">Thrown when tagname was null or empty.</exception>
        /// <exception cref="ArgumentException">Thrown when sort was set to GallerySortBy.Rising.</exception>
        /// <exception cref="ImgurException">Thrown when Imgur encounters an error.</exception>
        /// <returns>Information about the tag and an array of gallery submissions.</returns>
        public async Task <ITag> GetTagAsync(string tagname, GallerySortBy sort = GallerySortBy.Viral, GalleryWindow window = GalleryWindow.Week, uint page = 0)
        {
            if (string.IsNullOrEmpty(tagname))
            {
                throw new ArgumentNullException(nameof(tagname));
            }

            if (sort == GallerySortBy.Rising)
            {
                throw new ArgumentException(nameof(sort) + " cannot be Rising.");
            }

            var sortStr   = sort.ToString().ToLower();
            var windowStr = window.ToString().ToLower();

            var url = $"gallery/t/{tagname}/{sort}/{window}/{page}";

            using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url))
            {
                var tag = await SendRequestAsync <Tag>(request);

                return(tag);
            }
        }
コード例 #6
0
        /// <summary>
        /// View gallery images for a subreddit.
        /// </summary>
        /// <param name="sort">How to sort the results.</param>
        /// <param name="window">The maximum age of the items in the result.</param>
        /// <param name="page">The page of the result.</param>
        /// <param name="subreddit">A valid subreddit name</param>
        /// <exception cref="ArgumentNullException">Thrown when query was null or empty.</exception>
        /// <exception cref="ArgumentException">Thrown when sort was set to GallerySortBy.Rising.</exception>
        /// <exception cref="ImgurException">Thrown when Imgur encounters an error.</exception>
        /// <returns></returns>
        public async Task <ICollection <IGalleryRedditImage> > GetSubredditGalleryAsync(string subreddit, GallerySortBy sort = GallerySortBy.Viral, GalleryWindow window = GalleryWindow.Week, uint page = 0)
        {
            if (string.IsNullOrEmpty(subreddit))
            {
                throw new ArgumentNullException(nameof(subreddit));
            }

            var sortStr   = sort.ToString().ToLower();
            var windowStr = window.ToString().ToLower();
            var url       = $"gallery/r/{subreddit}/{sortStr}/{windowStr}/{page}";

            using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url))
            {
                var images = await SendRequestAsync <GalleryRedditImage[]>(request);

                return(images);
            }
        }
コード例 #7
0
        /// <summary>
        ///     View gallery items for a topic.
        /// </summary>
        /// <param name="topicId">The id of the topic.</param>
        /// <param name="sort">How to sort the items in a topic.</param>
        /// <param name="window">How old the items can be.</param>
        /// <param name="page">What page of the topic to fetch.</param>
        /// <returns>An array of gallery items.</returns>
        public async Task <ICollection <IGalleryAlbumImageBase> > GetTopicGalleryItemsAsync(int topicId, GallerySortBy sort = GallerySortBy.Viral, GalleryWindow window = GalleryWindow.Week, uint page = 0)
        {
            var sortStr   = sort.ToString().ToLower();
            var windowStr = window.ToString().ToLower();
            var url       = $"topics/{topicId}/{sortStr}/{windowStr}/{page}";

            using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url))
            {
                var items = await SendRequestAsync <IGalleryAlbumImageBase[]>(request);

                return(items);
            }
        }
コード例 #8
0
        /// <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);
            }
        }
コード例 #9
0
        /// <summary>
        ///     Search the gallery with a given query string.
        /// </summary>
        /// <param name="query">The query to use for searching.</param>
        /// <param name="sort">How to sort the results.</param>
        /// <param name="window">The maximum age of the items in the result.</param>
        /// <param name="page">The page of the result.</param>
        /// <exception cref="ArgumentNullException">Thrown when query was null or empty.</exception>
        /// <exception cref="ArgumentException">Thrown when sort was set to GallerySortBy.Rising.</exception>
        /// <exception cref="ImgurException">Thrown when Imgur encounters an error.</exception>
        /// <returns>An array of gallery submissions matching the query.</returns>
        public async Task <ICollection <IGalleryAlbumImageBase> > SearchGalleryAsync(string query, GallerySortBy sort = GallerySortBy.Time, GalleryWindow window = GalleryWindow.All, uint page = 0)
        {
            if (string.IsNullOrEmpty(query))
            {
                throw new ArgumentNullException(nameof(query));
            }

            if (sort == GallerySortBy.Rising)
            {
                throw new ArgumentException(nameof(sort) + " cannot be Rising.");
            }

            var sortStr   = sort.ToString().ToLower();
            var windowStr = window.ToString().ToLower();
            var queryStr  = WebUtility.UrlEncode(query);
            var url       = $"gallery/search/{sortStr}/{windowStr}/{page}?q={queryStr}";

            using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url))
            {
                var items = await SendRequestAsync <IGalleryAlbumImageBase[]>(request);

                return(items);
            }
        }