Ejemplo n.º 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;
            }
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
0
        /// <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));
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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);
            }
        }
        /// <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);
            }
        }
Ejemplo n.º 7
0
        private bool ParseUrlParameters(ActivityWindow activityWindow)
        {
            if (IsRunningOutOfBrowser)
            {
                return(false);
            }

            bool foundParam = false;

            if (queryString.ContainsKey(PARAMETER_ACTIVITY))
            {
                activityWindow.LoadOptions(makeActivityUri(queryString[PARAMETER_ACTIVITY]));
                foundParam = true;
            }

            if (queryString.ContainsKey(PARAMETER_MEDIA))
            {
                WaitTillNotBusy(activityWindow); //TODO: doesn't work (should wait for any activity to load first)
                MediaPlayerWindow w = new MediaPlayerWindow();
                w.Width  = activityWindow.Width;
                w.Height = activityWindow.Height - (activityWindow.ActivityView.ToolbarVisible ? 80 : 0); //TODO: should change this if/when activity toolbar is made vertical (have option to get ActualWidth/ActualHeight of activity toolbar)
                activityWindow.Container.AddWindowInViewCenter(w);
                w.MediaPlayerView.Source = makeClipUri(CLIPFLAIR_GALLERY_VIDEO, queryString[PARAMETER_MEDIA]);
                foundParam = true;
            }

            if (queryString.ContainsKey(PARAMETER_VIDEO))
            {
                WaitTillNotBusy(activityWindow); //TODO: doesn't work (should wait for any activity to load first)
                MediaPlayerWindow w = new MediaPlayerWindow();
                w.Width  = activityWindow.Width;
                w.Height = activityWindow.Height - (activityWindow.ActivityView.ToolbarVisible ? 80 : 0); //TODO: should change this if/when activity toolbar is made vertical (have option to get ActualWidth/ActualHeight of activity toolbar)
                activityWindow.Container.AddWindowInViewCenter(w);
                w.MediaPlayerView.Source = makeClipUri(CLIPFLAIR_GALLERY_VIDEO, queryString[PARAMETER_VIDEO]);
                foundParam = true;
            }

            if (queryString.ContainsKey(PARAMETER_AUDIO))
            {
                WaitTillNotBusy(activityWindow); //TODO: doesn't work (should wait for any activity to load first)
                MediaPlayerWindow w = new MediaPlayerWindow();
                w.Width  = activityWindow.Width;
                w.Height = 69; //Using small height since there's only audio //NOTE: if SMF skin changes this may not look ok
                activityWindow.Container.AddWindowInViewCenter(w);
                w.MediaPlayerView.VideoVisible = false;
                w.MediaPlayerView.Source       = new Uri(new Uri(CLIPFLAIR_GALLERY_AUDIO), queryString[PARAMETER_AUDIO]);
                foundParam = true;
            }

            if (queryString.ContainsKey(PARAMETER_IMAGE))
            {
                WaitTillNotBusy(activityWindow); //TODO: doesn't work (should wait for any activity to load first)
                ImageWindow w = new ImageWindow();
                w.Width  = activityWindow.Width;
                w.Height = activityWindow.Height - (activityWindow.ActivityView.ToolbarVisible ? 80 : 0); //TODO: should change this if/when activity toolbar is made vertical (have option to get ActualWidth/ActualHeight of activity toolbar)
                activityWindow.Container.AddWindowInViewCenter(w);
                w.ImageView.Source = new Uri(new Uri(CLIPFLAIR_GALLERY_IMAGE), queryString[PARAMETER_IMAGE]);
                foundParam         = true;
            }

            if (queryString.ContainsKey(PARAMETER_GALLERY))
            {
                WaitTillNotBusy(activityWindow); //TODO: doesn't work (should wait for any activity to load first)
                GalleryWindow w = new GalleryWindow();
                w.Width  = activityWindow.Width;
                w.Height = activityWindow.Height - (activityWindow.ActivityView.ToolbarVisible ? 80 : 0); //TODO: should change this if/when activity toolbar is made vertical (have option to get ActualWidth/ActualHeight of activity toolbar)
                activityWindow.Container.AddWindowInViewCenter(w);
                w.GalleryView.Source = makeGalleryUri(queryString[PARAMETER_GALLERY]);
                foundParam           = true;
            }

            if (queryString.ContainsKey(PARAMETER_COLLECTION))
            {
                WaitTillNotBusy(activityWindow); //TODO: doesn't work (should wait for any activity to load first)
                GalleryWindow w = new GalleryWindow();
                w.Width  = activityWindow.Width;
                w.Height = activityWindow.Height - (activityWindow.ActivityView.ToolbarVisible ? 80 : 0); //TODO: should change this if/when activity toolbar is made vertical (have option to get ActualWidth/ActualHeight of activity toolbar)
                activityWindow.Container.AddWindowInViewCenter(w);
                w.GalleryView.Source = makeGalleryUri(queryString[PARAMETER_COLLECTION]);
                foundParam           = true;
            }

            //TODO: add ...PARAMETER_CAPTIONS, PARAMETER_COMPONENT, TEXT, MAP etc.

            return(foundParam);
        } //TODO: add CAPTIONS parameter to load .SRT/.TTS/.SSA and show it
        /// <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>
        ///     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);
            }
        }
        /// <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);
            }
        }
        /// <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);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// View gallery images for a sub-reddit
        /// </summary>
        /// <param name="subreddit">A valid sub-reddit name</param>
        /// <param name="page">The current page</param>
        /// <param name="sort">The sort method (can't be viral)</param>
        /// <param name="window">Change the date range of the request if the section is "top"</param>
        public async Task <ImgurResponse <IGalleryObject[]> > GetSubredditGalleryAsync(string subreddit, int page = 0,
                                                                                       GallerySort sort           = GallerySort.Time, GalleryWindow window = GalleryWindow.Week)
        {
            if (ImgurClient.Authentication == null)
            {
                throw new InvalidAuthenticationException("Authentication can not be null. Set it in the main Imgur class.");
            }

            var endpoint = String.Format(GallerySubRedditUrl, subreddit, sort.ToString().ToLowerInvariant(),
                                         window.ToString().ToLowerInvariant(), page);

            return
                (await
                 Request.SubmitImgurRequestAsync(Request.HttpMethod.Get, endpoint, ImgurClient.Authentication,
                                                 customParser : ParseGalleryObjectArrayResponse));
        }